Foundations Syntax and Atoms Lesson 01
Orientation
Mental Model
A SJON document is a flat list of roots. Most authored files use one root form:
(scene :bpm 130)
Inside that form:
(scene ...)is a form.sceneis the form head.:bpm 130is a kvpair.130is an atom.
SJON itself does not know what scene means. A host application is the
program embedding SJON, such as a game engine, compiler, or build tool.
It loads one or more plugins, then validates the document against the
vocabulary those plugins provide. Ordinary .sjon files do not import
plugins.
Expressions use the same surface as data forms:
(camera :zoom (* 2 4))
(* 2 4) is just a form in source. It becomes a safe expression only
when the active schema says * is an expression function and the host
chooses to evaluate that value.
Worked Example
From ../../examples/basic.sjon:
(scene :bpm 130 :name "intro"
(canvas :name "main" :size [1920 1080]
(camera :ortho :zoom 2)
(stack :mode :overlay
(shape :sdf :radius 0.5 :color [0.9 0.4 0.2 1.0])
(shape :path :closed true
:points [[0 0] [1 0] [1 1] [0 1]]))
(placeholder :note "TODO" :enabled false :data nil)))
Read it as a tree:
- The document has one root: the
(scene ...)form. scenehas two kvpairs before its child::bpm 130and:name "intro".canvas,camera,stack,shape, andplaceholderare nested forms.[1920 1080],[0.9 0.4 0.2 1.0], and[[0 0] [1 0] [1 1] [0 1]]are vectors."intro"and"TODO"are strings.true,false, andnilare reserved literal atoms.:ortho,:sdf, and:pathare positional flags in this source. Two more flags are hiding in(stack :mode :overlay ...); section 5 explains why two consecutive keywords don’t pair into a kvpair.
Exercises
- Open
../../examples/basic.sjon. - Count the root values. Then count the forms.
- Mark each vector and write its likely role: size, color, point, or list of points.
- Find every string. Decide whether each string is a label, note, or payload.
- Find every positional flag. Do not decide whether the schema likes it yet; just identify the parse shape.
Repair drill:
:bpm 130
This cannot be a valid top-level kvpair because kvpairs only live inside forms. Repair it by wrapping it in a form:
(scene :bpm 130)
Mastery Check
-
Can a document have more than one root?
-
Does a
.sjonfile import plugins? -
Is
(* 2 4)always evaluated just because it looks like arithmetic? -
Where can a kvpair appear?