AST for TOML
February 24, 2026 ยท View on GitHub
See details: ../src/ast/ast.ts
You can see the AST on the Online DEMO.
Node
interface BaseTOMLNode {
type: string;
loc: SourceLocation;
range: [number, number];
}
All nodes have type, range, loc and parent properties according to ESLint - The AST specification.
Content Nodes
TOMLValue
type TOMLValue = TOMLStringValue | TOMLNumberValue | TOMLBooleanValue | TOMLDateTimeValue
// When expanded, it has the same definition as the following.
interface TOMLValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "string" | "integer" | "float" | "boolean" | "offset-date-time" | "local-date-time" | "local-date" | "local-time"
value: string | number | boolean | Date
parent: TOMLKey | TOMLKeyValue | TOMLArray
}
This is value.
kind... The kind of value. Each kind has more detailed properties.value... A value.
TOMLStringValue
interface TOMLStringValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "string"
value: string
style: "basic" | "literal"
multiline: boolean
parent: TOMLKeyValue | TOMLArray
}
This is String value.
e.g.
str1 = "Basic strings"
str2 = """
Multi-line
Basic strings"""
str3 = 'Literal strings'
str4 = '''
Multi-line
Literal strings'''
style... If"basic", the value was defined as (multi-line) basic string. If"literal", the value was defined as (multi-line) literal string.multiline... Iftrue, the value was defined as multi-line basic string or multi-line literal string.
TOMLIntegerValue
interface TOMLIntegerValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "integer"
value: number
bigint: bigint
number: string
parent: TOMLKeyValue | TOMLArray
}
This is Integer value.
e.g.
int = 42
value... The integer value defined by TOML. However, it can overflow.bigint... The integer value defined by TOML is stored as BigInt.number... The integer expressed as a string.
TOMLFloatValue
interface TOMLFloatValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "float"
value: number
number: string
parent: TOMLKeyValue | TOMLArray
}
This is Float value.
e.g.
float = 3.14
nan = nan
infinity = inf
value... The float value defined by TOML. The float containsNaNandInfinity.number... The float expressed as a string.
TOMLBooleanValue
interface TOMLBooleanValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "boolean"
value: boolean
parent: TOMLKeyValue | TOMLArray
}
This is Boolean.
e.g.
bool1 = true
bool2 = false
TOMLDateTimeValue
interface TOMLDateTimeValue extends BaseTOMLNode {
type: "TOMLValue"
kind: "offset-date-time" | "local-date-time" | "local-date" | "local-time"
value: Date
datetime: string
parent: TOMLKeyValue | TOMLArray
}
This is Offset Date-Time or Local Date-Time or Local Date or Local Time value.
e.g.
odt = 1979-05-27T07:32:00Z
ldt = 1979-05-27T07:32:00
ld = 1979-05-27
lt = 07:32:00
kind... If"offset-date-time", the value was defined as offset date-time. If"local-date-time", the value was defined as local date-time. If"local-date", the value was defined as local date. If"local-time", the value was defined as local time.value... The date is stored, but it may have been truncated to a value that can be represented by JavaScript.datetime... The date expressed as a string.
TOMLArray
interface TOMLArray extends BaseTOMLNode {
type: "TOMLArray"
elements: (TOMLValue | TOMLArray | TOMLInlineTable)[]
parent: TOMLKeyValue | TOMLArray
}
This is Array.
e.g.
array = [ 1, 2, 3]
TOMLInlineTable
interface TOMLInlineTable extends BaseTOMLNode {
type: "TOMLInlineTable"
body: TOMLKeyValue[]
parent: TOMLKeyValue | TOMLArray
}
This is Inline Table.
e.g.
name = { first = "Tom", last = "Preston-Werner" }
Key/Value Pair
TOMLKeyValue
interface TOMLKeyValue extends BaseTOMLNode {
type: "TOMLKeyValue"
key: TOMLKey
value: TOMLValue | TOMLArray | TOMLInlineTable
parent: TOMLTopLevelTable | TOMLTable | TOMLInlineTable
}
This is Key/Value Pair.
e.g.
key = "value"
TOMLKey
interface TOMLKey extends BaseTOMLNode {
type: "TOMLKey"
keys: (TOMLBare | TOMLStringKey)[]
parent: TOMLKeyValue | TOMLTable
}
This is Key.
e.g.
physical.color = "orange"
TOMLBare
interface TOMLBare extends BaseTOMLNode {
type: "TOMLBare"
name: string
parent: TOMLKey
}
This is Bare key.
e.g.
bare-key = 42
TOMLQuoted
interface TOMLQuoted extends BaseTOMLNode {
type: "TOMLQuoted"
value: string
style: "basic" | "literal"
parent: TOMLKey
}
This is Quoted key.
e.g.
"Key1" = 42
'Key2' = 42
Table
TOMLTable
interface TOMLTable extends BaseTOMLNode {
type: "TOMLTable"
kind: "standard" | "array"
key: TOMLKey
resolvedKey: (string | number)[]
body: TOMLKeyValue[]
parent: TOMLTopLevelTable
}
This is Table or Array of Table.
e.g.
[table]
key1 = "some string"
[[array.of.table]]
name = "Hammer"
sku = 738594937
[[array.of.table]]
name = "Nail"
sku = 284758393
kind... If"standard", the table was defined as[]. If"array", the table was defined as[[]].resolvedKey... An array of keys that are actually applied. In the above example, the first[[array.of.table]]is resolved as["array", "of", "table", 0], the second[[array.of.table]]is resolved as["array", "of", "table", 1].
Document
TOMLTopLevelTable
interface TOMLTopLevelTable extends BaseTOMLNode {
type: "TOMLTopLevelTable"
body: (TOMLKeyValue | TOMLTable)[]
parent: TOMLProgram
}
Program
interface TOMLProgram extends BaseTOMLNode {
type: "Program"
body: [TOMLTopLevelTable]
sourceType: "module"
comments: Comment[]
tokens: Token[]
parent: null
}
The body of the Program node generated by this parser is an array of TOMLTopLevelTable.