Skip to content

Full Syntax Reference

This document provides a complete, quick-reference guide to all syntax and features in the MON language. It serves as your go-to resource for understanding the data serialization syntax and configuration language syntax of MON.

A valid MON file can optionally start with one or more import statements, followed by a single root object.

// Optional imports first
import * as my_module from "./my_module.mon"
// Then, the single root object
{
// All content, including declarations and values, goes inside this object.
}
TypeExamples
String"hello", "with spaces"
Number123, -45.6
Booleantrue, false, on, off
Nullnull

Single-line comments start with //.

{
// This is a comment.
key: "value", // This is also a comment.
}
  • Objects are collections of key: value pairs inside {}.
  • Keys can be unquoted identifiers or quoted strings.
  • A trailing comma is allowed after the last member.
{
unquoted_key: "value",
"quoted-key-with-hyphens": 123,
}
  • Arrays are ordered lists of values inside [].
  • A trailing comma is allowed after the last element.
{
my_array: ["a", 1, true, null],
}
FeatureSyntaxDescription
Anchor&my_anchor: value,Gives a value a file-local nickname. Must be a key-value pair.
Alias*my_anchorCreates a deep copy of the anchored value.
Object Spread{ ...*my_anchor }Merges keys from an anchored object. Local keys override spread keys.
Array Spread[ ...*my_anchor ]Inserts elements from an anchored array into a new array.
FeatureSyntaxDescription
Enum DefinitionMyEnum: #enum { A, B },Defines a type with a fixed set of choices.
Enum Access$MyEnum.AReferences a specific variant of an enum.
Struct DefinitionMyStruct: #struct { f(T), g(N)=d },Defines a schema for an object. f is a required field of type T. g is an optional field of type N with a default value d.
Struct Validationmy_instance :: MyStruct = { ... }Validates that the object literal on the right conforms to the MyStruct schema.

Used within #struct field definitions (e.g., my_field([String...])).

PatternMeaning
[T]An array with exactly one element of type T.
[T...]An array with zero or more elements, all of type T.
[T1, T2]A tuple with exactly two elements of specified types.
[T1, T2...]An array with one or more elements, where the first is T1 and the rest are T2.
[T1..., T2]An array with one or more elements, where the last is T2 and the rest are T1.
AnyA special type that matches any value.

Import statements must be declared at the top of a file, before the root object.

  • Implicit Exports: All top-level keys in a file are importable.
  • Namespace Import: import * as ns from "./file.mon"
  • Named Import: import { Member1, &Anchor2 } from "./file.mon"