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

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

Parse error variants are organised into four broad groups:

  1. Path duplicates, where a key or table is defined more than once;
  2. Path traversal errors, where a key or table definition crosses a non-table value;
  3. Structural syntax errors when the produced tokens cannot represent part any valid TOML structure;
  4. 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 = 1 then a.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 } then a.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] then a.b = 3).

  • InvalidKeySyntax

    A key uses a syntax the spec does not allow (bare-key with invalid characters, missing/extra dots, etc.).

  • MissingValue

    A key/value pair with no value: key =. In TOML, values must begin on the same line as the key and equals sign.

  • ExtraEquals

    A key/value pair with more than one =: key = = 1.

  • MultipleValues

    A key/value pair with more than one value: key = 1 2.

  • EmptyTableHeader

    An empty table header: [] or [[]].

  • MalformedTableHeader

    A table header with mismatched brackets, invalid key tokens inside the brackets, or trailing junk after the closing bracket.

  • UnterminatedArray

    An 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 additional BadValue errors rather than as addressable nodes. This error requires manual correction before any index-based operations can be performed on the affected region.

  • MisplacedArraySeparator

    Misplaced/missing/extra commas between array elements.

  • UnterminatedInlineTable

    An 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 BadValue errors. Like UnterminatedArray, 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.

  • InvalidBareValueInInlineTable

    An entry inside an inline table that’s missing its = (a bare key or value with no key/value structure).

  • MisplacedInlineTableSeparator

    Misplaced, missing, or extra commas in an inline table.

  • UnterminatedString

    A 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.

  • UnterminatedMultilineString

    A 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.

  • UnparsableContent

    Content that the parser couldn’t make sense of (Error node in CST).

  • NoValidTomlStructure

    The 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

  • Root

    Root document node.

    node

  • Table

    A standard table header: [path.to.table]

    node

  • ArrayOfTables

    An array of tables header: [[path.to.array]]

    node

  • KeyValue

    A key/value pair: key = value

    node

  • Key

    A dotted key path: a.b.c

    node

  • Array

    An array value: [1, 2, 3]

    node

  • InlineTable

    An inline table value: {a = 1, b = 2}

    node

  • ArrayElement

    A single element within an array, carrying its value and associated trivia (comments).

    node

  • Error

    Unparsable content: the parser couldn’t make sense of this.

    node

  • PostScript

    Document 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

  • Bom

    UTF-8 Byte Order Mark at the start of a file

    token

  • BareKey

    A bare key: my-key, key123

    token

  • InvalidValue

    An unclassifiable token in value position

    token

  • InvalidBasicString

    An unterminated or otherwise invalid basic string: "hello\n

    token

  • InvalidLiteralString

    An unterminated or otherwise invalid literal string: 'hello\n

    token

  • InvalidMultilineBasicString

    An unterminated or otherwise invalid multiline basic string: """...

    token

  • InvalidMultilineLiteralString

    An unterminated or otherwise invalid multiline literal string: '''...

    token

  • BasicString

    A basic (double-quoted) string used as key or value: "hello"

    token

  • MultilineBasicString

    A multi-line basic string with no newline after the opening delimiter: """...""". The text field stores the raw content without delimiters.

    token

  • MultilineBasicStringNl

    A 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

  • LiteralString

    A literal (single-quoted) string used as key or value: 'hello'

    token

  • MultilineLiteralString

    A multi-line literal string with no newline after the opening delimiter: '''...'''. The text field stores the raw content without delimiters.

    token

  • MultilineLiteralStringNl

    A 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

  • Integer

    A decimal integer value

    token

  • BinaryInteger

    A binary integer value

    token

  • HexInteger

    A hex integer value

    token

  • OctalInteger

    An octal integer value

    token

  • Float

    A floating-point value

    token

  • BoolTrue

    A boolean true value.

    token

  • BoolFalse

    A boolean false value.

    token

  • Inf

    A floating point Infinity value (inf).

    token

  • PosInf

    A floating point positive Infinity value (+inf).

    token

  • NegInf

    A floating point negative Infinity value (-inf).

    token

  • NaN

    A floating point NaN value (nan).

    token

  • PosNaN

    A floating point positive NaN value (+nan).

    token

  • NegNaN

    A floating point negative NaN value (-nan).

    token

  • OffsetDateTime

    An offset date-time

    token

  • LocalDateTime

    A local date-time

    token

  • LocalDate

    A local date

    token

  • LocalTime

    A local time

    token

  • Equals

    =

    token

  • Dot

    .

    token

  • Comma

    ,

    token

  • LeftBracket

    [

    token

  • RightBracket

    ]

    token

  • LeftBrace

    {

    token

  • RightBrace

    }

    token

  • Comment

    A comment: # ... (includes the #)

    token

  • Whitespace

    Whitespace (spaces and tabs: not newlines)

    token

  • Newline

    A newline: \n or \r\n

    token

The TOML spec version to be supported.

pub opaque type TomlVersion

Values

pub const v1_0: TomlVersion

Marks a document as TOML 1.0 for output.

pub const v1_1: TomlVersion

Marks a document as TOML 1.1 for output.

Search Document