Syntax & Grammar
This document defines the syntax and grammar rules for the TON file format.
Document Structure
// Optional header
#@ tonVersion = '1', @schemaFile = 'schema.ton'
// Root object (required)
{(className)
// Properties
property1 = value1,
property2 = value2,
// Child objects
{(childClass)
childProperty = value
}
}
// Optional schema definitions
#! {(className)
/property1 = string(required),
/property2 = int(min(0))
}
Object Syntax
Objects are the fundamental structure in TON:
// Untyped object
{
property = value
}
// Typed object
{(typeName)
property = value
}
// Nested objects
{(parent)
property = value,
{(child)
childProperty = value
}
}
Property Rules
- Properties must appear before child objects
- Property names can be quoted or unquoted
- Values follow type-specific quoting rules
- Properties are separated by commas (trailing comma not allowed)
Array Syntax
// Simple array
[1, 2, 3]
// Mixed types
[1, "text", true, null]
// Nested arrays
[[1, 2], [3, 4]]
// Array of objects
[
{(item) id = 1, name = "First"},
{(item) id = 2, name = "Second"}
]
Type Hints
Optional prefixes to indicate expected types:
{
stringValue = $"explicitly a string",
numberValue = %42,
guidValue = &550e8400-e29b-41d4-a716-446655440000,
arrayValue = ^[1, 2, 3]
}
Grammar Rules (EBNF)
document = [header] object [schemas] header = "#@" property-list object = "{" [class-type] [property-list] [object-list] "}" class-type = "(" identifier ")" property-list = property ("," property)* property = property-name "=" value property-name = identifier | string | number | "@" identifier value = string | number | boolean | null | undefined | guid | date | enum | array | object array = "[" [value-list] "]" value-list = value ("," value)* schemas = schema+ schema = "#!" (object-schema | enum-schema)