Core syntax
The CX surface syntax — the data / document layer specified in lexicon.ebnf, grammar.ebnf, and code.md §3 / cxdm.md. Elements, attributes, scalars and type annotations, atoms, anchors / merges / ids, comments, raw and block content, entity references, namespaces, and table literals. Each example shows a source snippet and its cx fmt canonical render, pinned verbatim to the data conformance corpora.
element
[name attr=val CHILD…] — An element: a bracketed head name followed by optional attributes and a body of text, scalars, or nested elements.
Kind · structure
[input type=text name=q]
[input type=text name=q]
nested-elements
[parent [child …] …] — Elements nest as body children; whitespace between children is non-semantic and is normalised on render.
Kind · structure
[config
[db host=localhost port=5432]
[server port=8080]
]
[config
[db host=localhost port=5432]
[server port=8080]
]
mixed-content
[name TEXT [child] TEXT] — Mixed content interleaves bare text and child elements in one body; bare text runs render quoted.
Kind · structure
[p text [b bold] more]
[p 'text ' [b bold] ' more']
attribute
name=value — A scalar attribute on an element; the value auto-types (int, bool, atom, string) unless quoted.
Kind · attribute
[socket port=8080 protocol=:tcp]
[socket port=8080 protocol=:tcp]
boolean-scalar
[name true] / [name false] — Bare `true`/`false` in body position auto-type to booleans; quote them to keep a string.
Kind · scalar
[active true]
[active true]
null-scalar
[name null] — Bare `null` in body position auto-types to the null value.
Kind · scalar
[value null]
[value null]
quoted-string
[name 'value'] — A quoted body value is kept verbatim as a string — auto-typing is suppressed.
Kind · scalar
[status 'true']
[status 'true']
type-annotation
name::Type — A glued `::T` type annotation pins a scalar to an explicit type, overriding auto-typing.
Kind · annotation
[age::int 30]
[age::int 30]
atom
:NAME — An atom literal: an interned, type-strict symbolic scalar that never equals a same-spelled string.
Kind · scalar
[status :active]
[status :active]
atom-collection
[:a, :b] / (:a, :b) / {k: :v} — Atoms are first-class scalars usable inside arrays, sequences, and map values.
Kind · scalar
[transitions [:idle, :running, :complete]]
[transitions [:idle, :running, :complete]]
anchor
&name — An anchor labels an element so it can be aliased or merged elsewhere in the document.
Kind · identity
[defaults &def timeout=30 retries=3]
[defaults &def timeout=30 retries=3]
merge
*name — A merge pulls an anchored element's attributes into the current element (later attributes win).
Kind · identity
[defaults &def timeout=30 retries=3]
[production *def host=prod.example.com retries=5]
[defaults &def timeout=30 retries=3]
[production *def host=prod.example.com retries=5]
id
#id — An ID declaration names an element for reference; `@id` refers back to it.
Kind · identity
[user #u-1 name=alice]
[user #u-1 name=alice]
id-reference
@id — An IDREF refers to a declared `#id`; forward references resolve.
Kind · identity
[users
[user #u-1 name=alice]
[reviewer assigned-to=@u-1]
]
[users
[user #u-1 name=alice]
[reviewer assigned-to=@u-1]
]
block-content
[| … |] — Block content: a verbatim text block delimited by `[|` and `|]`.
Kind · structure
[p [|hello world|]]
[p [|hello world|]]
comment
[; … ] — A block comment `[; … ]` is preserved by the lossless formatter and dropped by the strict canonical form.
Kind · comment
[;a comment]
[p text]
[;a comment]
[p text]
raw-text
[# … #] — Raw text / CDATA: content between `[#` and `#]` is taken literally (no parsing) — distinct from a comment.
Kind · structure
entity-reference
&name; / nnn; — Entity and character references in text: named XML entities and numeric character references are recognised.
Kind · scalar
[p & < >]
[p & < >]
namespace
xmlns:prefix=URI / prefix:name — XML namespaces: declare with `xmlns` / `xmlns:prefix` and qualify names as `prefix:local`.
Kind · namespace
[doc xmlns:dc=http://purl.org/dc/elements/1.1/
[dc:title Hello]
]
[doc xmlns:dc=http://purl.org/dc/elements/1.1/
[dc:title Hello]
]
table
[table[col::T …]] ROW… — A typed table literal: a column header (`[table[…]]`) followed by whitespace-separated cell rows.
Kind · table
[users [table[name::string age::int active::bool]]
alice 30 true
bob 25 false
]
[users [table[name::string age::int active::bool]]
alice 30 true
bob 25 false
]