MON means Moth Object Notation. MON syntax gives supplied arguments and record values a common notation. Pipes declare fields or parameters. Parentheses supply values or group an expression.
Size = |
width I32,
height I32,
|
size = Size(width = 1280, height = 720)
settings #= (
title = "Strategy",
window = (width = 1280, height = 720),
)
Every anonymous field has a name and a value. Records can nest directly. #= requires all their values to be known during compilation.
(value) groups an expression. (name = value) constructs a one-field record. Commas separate entries, and a final comma is optional. Moth has no tuple values. The label and = share one logical line. The value may start on the next line.
Named types still need their constructors. An anonymous record with matching fields does not become a Size.
Moth MON source syntax allows ordinary expressions according to the receiving Moth context. MON serialised data is self-contained literal data only, and a MON reader never evaluates Moth expressions, including foldable ones.
MON format owns the serialised literal-data contract. This page owns the shared notation only.
MON syntax alone does not turn a record into serialised text or make every Moth value serialisable.
MON means Moth Object Notation. MON syntax names Moth's shared parenthesised argument and value-construction notation. The MON format is the separate serialised-data profile with its own supported values and serialisation rules. Using MON syntax does not make a value serialisable or turn a call into a data document.
This reference owns the shared notation and the distinction between grouping, supplied arguments and anonymous construction. Calls, constructors, directives and const or runtime records retain their own semantic contracts.
Declarations and supplied values
Pipes enclose declared parameters and typed nominal fields. Parentheses supply values or group an expression.
Size = |
width I32,
height I32,
|
size = Size(width = 1280, height = 720)
A nominal value uses its named constructor. Matching field names do not make an anonymous record a Size. MON syntax adds no implicit nominal construction, structural typing, argument spreading or tuple values.
Declaration lists remain flat. A legal default expression may contain nested value construction without introducing a nested type declaration. Defaults still need the type and compile-time evidence their receiving declaration requires.
Grouping and records
A single unnamed expression in parentheses is grouping. A named initializer selects anonymous record construction, including a record with one field.
total #= (1 + 2)
label #= (name = "Moth")
labels #= (first = "Priya", second = "Rob",)
empty #= ()
A comma separates entries. It does not create a tuple or infer a field name. (value,), (first, second) and (,) are invalid value constructions. Expression-position () is an empty const record when the receiving context requires a compile-time value. Empty runtime records are outside the initial runtime surface. Neither case introduces a unit type.
(calculate(x = 1, y = 2)) groups a call. Names and commas inside that inner call do not classify the outer parentheses. Grouping preserves ordinary precedence, place access, postfix operations and immediate cast-target rules.
Entries and layout
Every anonymous entry has a unique identifier and an explicit label = expression entry. It requires at least one horizontal whitespace character before = and whitespace immediately after it. Its type is inferred from the expression. Entries have no type annotation, declaration qualifier, default, omitted value or field-level mutable declaration. There are no positional anonymous fields or implicit name shorthands.
Use commas between entries. One trailing comma is allowed. Blank lines and comments may separate entries. The label and = must share one logical line. LF and CR are the only line breaks, with CRLF counting as one break; every other Unicode whitespace character is horizontal whitespace and may separate them. At least one whitespace character must immediately follow =, and it may be a line break, so the value can start on the next line. The same named-entry boundary applies to MON, including implicit and explicit roots, nested records and qualified payloads. Newlines do not replace commas or join an incomplete label to a later assignment.
Map entry = also requires whitespace on both sides. MON's {=} empty-map spelling is the exception because it is not a non-empty map entry.
A field label does not bind a local name. Every initializer resolves names in the surrounding scope. Earlier fields are not bare names visible to later fields.
title #= "Strategy"
panel #= (
title = title,
details = (title = "Overview"),
)
The two title labels belong to different records and do not conflict. Duplicate labels within the same record are invalid.
Each initializer supplies one value. Multiple return slots cannot become a tuple field or expand into several entries. A field label supplies no expected type for an otherwise untyped none, empty container or cast. Use an earlier typed value when its type cannot be inferred. The existing expression rules decide which empty literals can infer their own type.
Recursive construction
Anonymous values nest directly. Named nominal children still use their constructors.
Size = |
width I32,
height I32,
|
settings #= (
window = (
title = "Strategy",
size = Size(width = 1280, height = 720),
),
)
width #= settings.window.size.width
#= requires the complete value to fold, including every nested field. It does not grant new compile-time execution capabilities. A runtime receiving context selects the separate runtime-record contract even when all fields look constant.
Const records owns folded fields and runtime-use restrictions. Runtime anonymous records owns hidden nominal identity, local composition and escape restrictions.
Context determines argument policy
Calls, constructors and directives share MON list syntax without sharing every permitted argument or value category.
- User calls and named constructors keep positional-then-named signature routing.
- Host calls and builtin members keep their positional-only contracts.
- Anonymous records require named entries and establish their own fields.
- Directive arguments require compile-time values and their registered categories.
A known signature supplies parameter names, types and defaults. An anonymous record has no callee signature or omitted default slots. Shared syntax changes neither evaluation order nor the ordinary access, coercion and error rules.
consume(x = 1) supplies the argument named x. consume((x = 1)) supplies one record expression, whose legality still depends on record and parameter rules. There is no automatic record-to-argument expansion.
Ordinary f() is a zero-argument call. The accepted directive contract uses bare $name when no arguments are supplied and rejects $name(). Template labels, indices and helper wrappers retain their specialised meanings.
Shared construction parity
For a supported common literal form in the same language and format revision, equivalent exact receiving types or schemas require both parsers to accept the form and produce the same typed value. Source and MON keep independent parsers: compiler-local owners parse calls and declarations, while moth-mon parses literal data. Both consume identifier, reserved-word and numeric text facts from moth-lexical. The real-source conformance suite at src/compiler_tests/mon_syntax_parity/ checks each expected outcome before comparing typed values.
Nominal constructor names and choice variant names take a payload only when ( follows on the same logical line with only horizontal whitespace between. LF, CR or a line comment between the head and ( means there is no payload; the following input fails through ordinary parsing. Source and MON share this head rule. Newlines inside argument lists and after = remain valid, and the existing adjacency restriction between :: and its variant name is unchanged.
Common invalid forms must fail in both parsers for the expected reason. Intentional data/source differences include:
- MON frames one root record, including implicit and empty roots. Source receivers also accept expression fragments.
- A MON schema supplies field and nominal shape. Source infers anonymous records and requires explicit nominal constructors.
- MON contains literal values only. Expressions, bindings, imports, mutable access and declarations remain source syntax.
- MON preserves raw quoted text and uses its own bounded escapes. Source quoted slices have separate escape and line-ending rules.
- MON applies codec text, nesting, node and materialisation budgets. These are not source grammar limits.
This contract does not make an arbitrary MON document pasteable anywhere in Moth. Document framing, supplied schema information and legal source receiving contexts still matter. An anonymous source record does not implicitly construct a nominal struct just because a MON schema can receive that record as struct data.
MON format boundary
Moth MON source syntax allows ordinary expressions according to the receiving Moth context. MON serialised data is self-contained literal data only. A MON reader never evaluates Moth expressions, including foldable ones.
MON format owns the serialised literal-data contract: one root record, literal-only values, strict numeric conversion, qualifiers, defaults and bounded first errors. This reference owns the shared notation and the distinction between grouping, supplied arguments and anonymous construction.
The standalone moth_mon codec serves independent Rust callers. Compiler clients can use the same API and Rust types through the convenience re-export moth::mon. The engine or application supplies its own data schema.
Full compile-time Moth authoring expressions and the self-contained serialised representation are distinct surfaces.
Templates remain ordinary strings. MON syntax adds no automatic record printing, implicit live bindings, stored Wire capabilities or executable Route values.