molt/types
Shared types for molt, molt/cst, molt/ops, and molt/value.
Types
A parsed TOML document.
Produced by molt.parse and operated on by most other molt
functions.
The version field controls how the document is output, see
molt.set_version.
error_count is the number of validation errors found in the document.
It must be zero before most document-level functions can operate. Inspect it
with molt.has_errors / molt.error_count, or retrieve the full list of
positioned errors with molt.document_errors.
The tree and index fields are internal and should not be accessed
directly; use molt/cst for direct tree operations.
pub type Document {
Document(
version: TomlVersion,
error_count: Int,
tree: greenwood.Node(TomlKind),
index: option.Option(
dict.Dict(@internal IndexKey, @internal IndexEntry),
),
)
}
Constructors
-
Document( version: TomlVersion, error_count: Int, tree: greenwood.Node(TomlKind), index: option.Option( dict.Dict(@internal IndexKey, @internal IndexEntry), ), )
A path addressing a node in the document, a list of path segments.
pub type Path =
List(PathSegment)
A segment in a document path.
pub type PathSegment {
KeySegment(String)
IndexSegment(Int)
}
Constructors
-
KeySegment(String)A key name.
-
IndexSegment(Int)A zero-based index into an array or array table. Negative counts from end.
A position in the source document.
pub type Span {
Span(line: Int, col: Int, offset: Int)
}
Constructors
-
Span(line: Int, col: Int, offset: Int)
A recoverable error found during parsing or validation. These do not prevent CST construction but block index-building and high-level operations.
pub type SyntaxError {
SyntaxError(
kind: SyntaxErrorKind,
path: List(String),
span: Span,
)
}
Constructors
-
SyntaxError( kind: SyntaxErrorKind, path: List(String), span: Span, )
Parse error variants are organised into four broad groups:
- Path duplicates, where a key or table is defined more than once;
- Path traversal errors, where a key or table definition crosses a non-table value;
- Structural syntax errors when the produced tokens cannot represent part any valid TOML structure;
- Other errors including unparsable content.
When SyntaxErrorKind variants have an original Span, this always refers
to the original declaration and the Span in the SyntaxError refers to the
current instance.
pub type SyntaxErrorKind {
DuplicateKey(key: String, original: Span)
DuplicateTable(original: Span)
KeyIsScalar(key: String, original: Span)
KeyIsInlineTable(key: String, original: Span)
KeyIsArray(key: String, original: Span)
InvalidKeySyntax
MissingValue
ExtraEquals
MultipleValues
EmptyTableHeader
MalformedTableHeader
UnterminatedArray
MisplacedArraySeparator
UnterminatedInlineTable
DuplicateKeyInInlineTable(key: String)
InvalidBareValueInInlineTable
MisplacedInlineTableSeparator
UnterminatedString
UnterminatedMultilineString
BadValue(text: String)
UnparsableContent
NoValidTomlStructure
}
Constructors
-
DuplicateKey(key: String, original: Span)A key was declared twice within the same table scope.
-
DuplicateTable(original: Span)A
[table]or[[array of tables]]header collides with an existing explicit table or array of tables definition. -
KeyIsScalar(key: String, original: Span)A dotted key or table header tries to descend through an ancestor key that is bound to a scalar value (
a = 1thena.b = 2, or[a.b]). -
KeyIsInlineTable(key: String, original: Span)A dotted key or table header tries to descend through an ancestor key that is bound to an inline table (
a = { b = 1 }thena.c = 2). -
KeyIsArray(key: String, original: Span)A dotted key or table header tries to descend through an ancestor key that is bound to an inline array (
a = [1, 2]thena.b = 3). -
InvalidKeySyntaxA key uses a syntax the spec does not allow (bare-key with invalid characters, missing/extra dots, etc.).
-
MissingValueA key/value pair with no value:
key =. In TOML, values must begin on the same line as the key and equals sign. -
ExtraEqualsA key/value pair with more than one
=:key = = 1. -
MultipleValuesA key/value pair with more than one value:
key = 1 2. -
EmptyTableHeaderAn empty table header:
[]or[[]]. -
MalformedTableHeaderA table header with mismatched brackets, invalid key tokens inside the brackets, or trailing junk after the closing bracket.
-
UnterminatedArrayAn array opened with
[but not closed before end of document. Because the array scanner consumes subsequent lines until it finds a closing]or runs out of source, all document content after the opening[is structurally broken: table headers and key/value pairs that follow are misclassified as array elements and appear as additionalBadValueerrors rather than as addressable nodes. This error requires manual correction before any index-based operations can be performed on the affected region. -
MisplacedArraySeparatorMisplaced/missing/extra commas between array elements.
-
UnterminatedInlineTableAn inline table opened with
{but not closed before end-of-line.All content on subsequent lines is consumed as inline table entries and misclassified, producing cascading
BadValueerrors. LikeUnterminatedArray, this requires manual correction before index-based operations are reliable past the opening{. -
DuplicateKeyInInlineTable(key: String)A key declared more than once inside an inline table.
-
InvalidBareValueInInlineTableAn entry inside an inline table that’s missing its
=(a bare key or value with no key/value structure). -
MisplacedInlineTableSeparatorMisplaced, missing, or extra commas in an inline table.
-
UnterminatedStringA basic (
") or literal (') string that was not closed before end-of-line. The rest of the document is unaffected and other operations on the CST remain valid. -
UnterminatedMultilineStringA multiline basic (
""") or literal (''') string that was not closed before end of document. Because the multiline scanner consumes input until it finds the closing delimiter or runs out of source, all document content after the opening delimiter is lost from the CST. This error should be reported to the user as requiring manual correction before any further operations can be performed. -
BadValue(text: String)An unclassifiable token in value position.
-
UnparsableContentContent that the parser couldn’t make sense of (Error node in CST).
-
NoValidTomlStructureThe source has non-trivia content but no recognisable TOML structure (e.g. no
=and no[).
TOML Parser kinds for the concrete syntax tree.
pub type TomlKind {
Root
Table
ArrayOfTables
KeyValue
Key
Array
InlineTable
ArrayElement
Error
PostScript
Bom
BareKey
InvalidValue
InvalidBasicString
InvalidLiteralString
InvalidMultilineBasicString
InvalidMultilineLiteralString
BasicString
MultilineBasicString
MultilineBasicStringNl
LiteralString
MultilineLiteralString
MultilineLiteralStringNl
Integer
BinaryInteger
HexInteger
OctalInteger
Float
BoolTrue
BoolFalse
Inf
PosInf
NegInf
NaN
PosNaN
NegNaN
OffsetDateTime
LocalDateTime
LocalDate
LocalTime
Equals
Dot
Comma
LeftBracket
RightBracket
LeftBrace
RightBrace
Comment
Whitespace
Newline
}
Constructors
-
RootRoot document node.
node -
TableA standard table header:
[path.to.table]node -
ArrayOfTablesAn array of tables header:
[[path.to.array]]node -
KeyValueA key/value pair:
key = valuenode -
KeyA dotted key path:
a.b.cnode -
ArrayAn array value:
[1, 2, 3]node -
InlineTableAn inline table value:
{a = 1, b = 2}node -
ArrayElementA single element within an array, carrying its value and associated trivia (comments).
node -
ErrorUnparsable content: the parser couldn’t make sense of this.
node -
PostScriptDocument tail: a tombstone node holding any trivia (comments / blank lines) that dangles after the final statement. Like
Root, it carries leading trivia only and emits no content of its own; it exists so document-tail comments have a node to attach to (get_document_comments(_, Tail)).Tail comments are stored in this position after all value nodes. When rendered, a newline may be placed between the final value node and these comments: a parsed tail keeps the source’s spacing, while setting the tail (and normalizing) always separates it from the content with a blank line.
node -
BomUTF-8 Byte Order Mark at the start of a file
token -
BareKeyA bare key:
my-key,key123token -
InvalidValueAn unclassifiable token in value position
token -
InvalidBasicStringAn unterminated or otherwise invalid basic string:
"hello\ntoken -
InvalidLiteralStringAn unterminated or otherwise invalid literal string:
'hello\ntoken -
InvalidMultilineBasicStringAn unterminated or otherwise invalid multiline basic string:
"""...token -
InvalidMultilineLiteralStringAn unterminated or otherwise invalid multiline literal string:
'''...token -
BasicStringA basic (double-quoted) string used as key or value:
"hello"token -
MultilineBasicStringA multi-line basic string with no newline after the opening delimiter:
"""...""". The text field stores the raw content without delimiters.token -
MultilineBasicStringNlA multi-line basic string with a newline immediately after the opening delimiter:
"""\n...""". The text field stores the raw content without delimiters or the leading newline (which is encoded in the kind itself).token -
LiteralStringA literal (single-quoted) string used as key or value:
'hello'token -
MultilineLiteralStringA multi-line literal string with no newline after the opening delimiter:
'''...'''. The text field stores the raw content without delimiters.token -
MultilineLiteralStringNlA multi-line literal string with a newline immediately after the opening delimiter:
'''\n...'''. The text field stores the raw content without delimiters or the leading newline (which is encoded in the kind itself).token -
IntegerA decimal integer value
token -
BinaryIntegerA binary integer value
token -
HexIntegerA hex integer value
token -
OctalIntegerAn octal integer value
token -
FloatA floating-point value
token -
BoolTrueA boolean
truevalue.token -
BoolFalseA boolean
falsevalue.token -
InfA floating point Infinity value (
inf).token -
PosInfA floating point positive Infinity value (
+inf).token -
NegInfA floating point negative Infinity value (
-inf).token -
NaNA floating point NaN value (
nan).token -
PosNaNA floating point positive NaN value (
+nan).token -
NegNaNA floating point negative NaN value (
-nan).token -
OffsetDateTimeAn offset date-time
token -
LocalDateTimeA local date-time
token -
LocalDateA local date
token -
LocalTimeA local time
token -
Equals=token -
Dot.token -
Comma,token -
LeftBracket[token -
RightBracket]token -
LeftBrace{token -
RightBrace}token -
CommentA comment:
# ...(includes the#)token -
WhitespaceWhitespace (spaces and tabs: not newlines)
token -
NewlineA newline:
\nor\r\ntoken
The TOML spec version to be supported.
pub opaque type TomlVersion