feat: unflatten structure and rename nodes (#4)

Since the AST should reflect its logical structure as close as possible, I revert the changes from #2. This PR also renames nodes with more appropriate names.

BREAKING CHANGE:

- rename `file` with `document`.
- rename `table_array` with `table_array_element`.
- unflatten `table` and `table_array_element`, i.e., `pair`s are now their children instead of siblings.
This commit is contained in:
Ika 2019-08-31 22:16:56 +08:00 committed by GitHub
parent 000f53ee75
commit 42afd6a0eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 2391 additions and 2287 deletions

View file

@ -4,7 +4,7 @@ VALID - empty file
--------------------------------------------------------------------------------
(file)
(document)
================================================================================
INVALID - key/value pair - multiline string for keys are not allowed
@ -26,7 +26,7 @@ key
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (ERROR) (boolean))
(pair
@ -42,10 +42,9 @@ invalid_both = 1 .0 e 2
--------------------------------------------------------------------------------
(file
(document
(ERROR
(dotted_key
(key) (ERROR) (key))))
(key) (integer)))
================================================================================
INVALID - offset date time - whitespaces between its components are not allowed
@ -56,7 +55,7 @@ invalid2 = 1979-05-27 T 07:32:00 Z
--------------------------------------------------------------------------------
(file
(document
(ERROR
(key) (local_date) (local_time) (local_time)))
@ -69,7 +68,7 @@ invalid2 = 1979-05-27 T 07:32:00
--------------------------------------------------------------------------------
(file
(document
(ERROR
(key) (local_date) (local_time) (local_time)))
@ -81,7 +80,7 @@ valid = 1979-05-27
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (local_date)))
@ -105,7 +104,7 @@ key
--------------------------------------------------------------------------------
(file
(document
(table
(key) (ERROR))
(table
@ -121,7 +120,7 @@ key = {
--------------------------------------------------------------------------------
(file
(document
(pair
(key)
(inline_table
@ -150,7 +149,7 @@ key
--------------------------------------------------------------------------------
(file
(document
(ERROR
(key) (key)))
@ -164,10 +163,9 @@ VALID - table - empty content separated by comments
--------------------------------------------------------------------------------
(file
(document
(table
(key))
(comment))
(key) (comment)))
================================================================================
VALID - array of tables - empty content separated by comments
@ -179,10 +177,9 @@ VALID - array of tables - empty content separated by comments
--------------------------------------------------------------------------------
(file
(table_array
(key))
(comment))
(document
(table_array_element
(key) (comment)))
================================================================================
VALID - table - two pairs separated by comments
@ -198,14 +195,14 @@ b = 2
--------------------------------------------------------------------------------
(file
(document
(table
(key))
(pair
(key) (integer))
(comment)
(pair
(key) (integer)))
(key)
(pair
(key) (integer))
(comment)
(pair
(key) (integer))))
================================================================================
VALID - array of tables - two pairs separated by comments
@ -221,11 +218,11 @@ b = 2
--------------------------------------------------------------------------------
(file
(table_array
(key))
(pair
(key) (integer))
(comment)
(pair
(key) (integer)))
(document
(table_array_element
(key)
(pair
(key) (integer))
(comment)
(pair
(key) (integer))))

View file

@ -7,7 +7,7 @@ key = "value" # This is a comment at the end of a line
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (string) (comment)))
@ -20,7 +20,7 @@ key = "value"
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string)))
@ -32,7 +32,7 @@ key = # INVALID
--------------------------------------------------------------------------------
(file
(document
(ERROR
(key) (comment)))
@ -47,7 +47,7 @@ bare-key = "value"
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string))
(pair
@ -69,7 +69,7 @@ VALID - keys - quoted keys
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string))
(pair
@ -91,7 +91,7 @@ INVALID - keys - empty bare key
--------------------------------------------------------------------------------
(file
(document
(pair
(key
(MISSING _bare_key))
@ -113,7 +113,7 @@ site."google.com" = true
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string))
(pair
@ -139,7 +139,7 @@ name = "Pradyun"
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (string))
@ -155,7 +155,7 @@ a.d = 2
--------------------------------------------------------------------------------
(file
(document
(pair
(dotted_key
(dotted_key
@ -177,7 +177,7 @@ a.b.c = 2
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(dotted_key
@ -198,7 +198,7 @@ str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
--------------------------------------------------------------------------------
(file
(document
(pair
(key)
(string
@ -214,7 +214,7 @@ Violets are blue"""
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string)))
@ -240,7 +240,7 @@ str3 = """\
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (string))
@ -265,7 +265,7 @@ regex = '<\i\c*\s*>'
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (string))
@ -290,7 +290,7 @@ trimmed in raw strings.
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (string))
(pair
@ -307,7 +307,7 @@ int4 = -17
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (integer))
(pair
@ -327,7 +327,7 @@ int7 = 1_2_3_4_5 # VALID but discouraged
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (integer))
(pair
@ -353,7 +353,7 @@ bin1 = 0b11010110
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (integer))
@ -389,7 +389,7 @@ flt7 = 6.626e-34
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (float))
@ -416,7 +416,7 @@ flt8 = 9_224_617.445_991_228_313
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (float)))
@ -436,7 +436,7 @@ sf6 = -nan # valid, actual encoding is implementation specific
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (float) (comment))
@ -461,7 +461,7 @@ bool2 = false
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (boolean))
(pair
@ -477,7 +477,7 @@ odt3 = 1979-05-27T00:32:00.999999-07:00
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (offset_date_time))
(pair
@ -493,7 +493,7 @@ odt4 = 1979-05-27 07:32:00Z
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (offset_date_time)))
@ -506,7 +506,7 @@ ldt2 = 1979-05-27T00:32:00.999999
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (local_date_time))
(pair
@ -520,7 +520,7 @@ ld1 = 1979-05-27
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (local_date)))
@ -533,7 +533,7 @@ lt2 = 00:32:00.999999
--------------------------------------------------------------------------------
(file
(document
(pair
(key) (local_time))
(pair
@ -553,7 +553,7 @@ arr6 = [ 1, 2.0 ] # INVALID
--------------------------------------------------------------------------------
(file
(document
(pair
(key)
(array
@ -601,7 +601,7 @@ arr8 = [
--------------------------------------------------------------------------------
(file
(document
(pair
(key)
(array
@ -619,7 +619,7 @@ VALID - table - header
--------------------------------------------------------------------------------
(file
(document
(table
(key)))
@ -637,19 +637,19 @@ key2 = 456
--------------------------------------------------------------------------------
(file
(document
(table
(key))
(pair
(key) (string))
(pair
(key) (integer))
(key)
(pair
(key) (string))
(pair
(key) (integer)))
(table
(key))
(pair
(key) (string))
(pair
(key) (integer)))
(key)
(pair
(key) (string))
(pair
(key) (integer))))
================================================================================
VALID - table - header with dotted key
@ -660,14 +660,14 @@ type.name = "pug"
--------------------------------------------------------------------------------
(file
(document
(table
(dotted_key
(key) (key)))
(pair
(dotted_key
(key) (key))
(string)))
(pair
(dotted_key
(key) (key))
(string))))
================================================================================
VALID - table- header with whitespaces
@ -680,7 +680,7 @@ VALID - table- header with whitespaces
--------------------------------------------------------------------------------
(file
(document
(table
(dotted_key
(dotted_key
@ -717,7 +717,7 @@ VALID - table - directly defined nested header key
--------------------------------------------------------------------------------
(file
(document
(comment)
(comment)
(comment)
@ -744,16 +744,16 @@ c = 2
--------------------------------------------------------------------------------
(file
(document
(comment)
(table
(key))
(pair
(key) (integer))
(key)
(pair
(key) (integer)))
(table
(key))
(pair
(key) (integer)))
(key)
(pair
(key) (integer))))
================================================================================
VALID - table - overlapped header key (semantically INVALID)
@ -769,17 +769,17 @@ c = 2
--------------------------------------------------------------------------------
(file
(document
(comment)
(table
(key))
(pair
(key) (integer))
(key)
(pair
(key) (integer)))
(table
(dotted_key
(key) (key)))
(pair
(key) (integer)))
(key) (key))
(pair
(key) (integer))))
================================================================================
VALID - inline table - basic
@ -791,7 +791,7 @@ animal = { type.name = "pug" }
--------------------------------------------------------------------------------
(file
(document
(pair
(key)
(inline_table
@ -831,23 +831,23 @@ color = "gray"
--------------------------------------------------------------------------------
(file
(table_array
(document
(table_array_element
(key)
(pair
(key) (string))
(pair
(key) (integer)))
(table_array_element
(key))
(pair
(key) (string))
(pair
(key) (integer))
(table_array
(key))
(table_array
(key))
(pair
(key) (string))
(pair
(key) (integer))
(pair
(key) (string)))
(table_array_element
(key)
(pair
(key) (string))
(pair
(key) (integer))
(pair
(key) (string))))
================================================================================
VALID - array of tables - nested arrays of tables
@ -874,37 +874,37 @@ VALID - array of tables - nested arrays of tables
--------------------------------------------------------------------------------
(file
(table_array
(key))
(pair
(key) (string))
(document
(table_array_element
(key)
(pair
(key) (string)))
(table
(dotted_key
(key) (key)))
(pair
(key) (string))
(pair
(key) (string))
(table_array
(key) (key))
(pair
(key) (string))
(pair
(key) (string)))
(table_array_element
(dotted_key
(key) (key)))
(pair
(key) (string))
(table_array
(key) (key))
(pair
(key) (string)))
(table_array_element
(dotted_key
(key) (key)))
(pair
(key) (string))
(table_array
(key))
(pair
(key) (string))
(table_array
(key) (key))
(pair
(key) (string)))
(table_array_element
(key)
(pair
(key) (string)))
(table_array_element
(dotted_key
(key) (key)))
(pair
(key) (string)))
(key) (key))
(pair
(key) (string))))
================================================================================
VALID - array of tables - append to statically defined array (semantically INVALID)
@ -917,11 +917,11 @@ fruit = []
--------------------------------------------------------------------------------
(file
(document
(comment)
(pair
(key) (array))
(table_array
(table_array_element
(key) (comment)))
================================================================================
@ -941,20 +941,20 @@ VALID - array of tables - append to table (semantically INVALID)
--------------------------------------------------------------------------------
(file
(document
(comment)
(table_array
(key))
(pair
(key) (string))
(table_array
(table_array_element
(key)
(pair
(key) (string)))
(table_array_element
(dotted_key
(key) (key)))
(pair
(key) (string))
(comment)
(key) (key))
(pair
(key) (string))
(comment))
(table
(dotted_key
(key) (key)))
(pair
(key) (string)))
(key) (key))
(pair
(key) (string))))

View file

@ -2,18 +2,16 @@ const { Charset } = require("regexp-util");
const getInverseRegex = charset =>
new RegExp(`[^${charset.toString().slice(1, -1)}]`);
const concatRegex = (...regexes) =>
new RegExp(regexes.reduce((a, b) => a.concat(`(${b.source})`), []).join(""));
const control_chars = new Charset([0x0, 0x1f], 0x7f);
const newline = /(\r?\n)+/;
const newline = /\r?\n/;
const decimal_integer = /[+-]?(0|[1-9](_?[0-9])*)/;
const hexadecimal_integer = /0x[0-9a-fA-F](_?[0-9a-fA-F])*/;
const octal_integer = /0o[0-7](_?[0-7])*/;
const binary_integer = /0b[01](_?[01])*/;
const float_fractional_part = /[.][0-9](_?[0-9])*/;
const float_exponent_part = concatRegex(/[eE]/, decimal_integer);
const float_exponent_part = seq(/[eE]/, decimal_integer);
const rfc3339_date = /([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])/;
const rfc3339_delimiter = /[ tT]/;
@ -28,16 +26,31 @@ module.exports = grammar({
extras: $ => [$.comment, /[ \t]/],
rules: {
file: $ => repeat(choice($.pair, $.table, $.table_array, $._newline)),
document: $ =>
seq(
repeat(choice($.pair, newline)),
repeat(choice($.table, $.table_array_element)),
),
comment: $ => /#.*/,
_newline: $ => newline,
table: $ =>
seq("[", choice($.dotted_key, $.key), "]", $._line_ending_or_eof),
seq(
"[",
choice($.dotted_key, $.key),
"]",
$._line_ending_or_eof,
repeat(choice($.pair, newline)),
),
table_array: $ =>
seq("[[", choice($.dotted_key, $.key), "]]", $._line_ending_or_eof),
table_array_element: $ =>
seq(
"[[",
choice($.dotted_key, $.key),
"]]",
$._line_ending_or_eof,
repeat(choice($.pair, newline)),
),
pair: $ => seq($._inline_pair, $._line_ending_or_eof),
_inline_pair: $ => seq(choice($.dotted_key, $.key), "=", $._inline_value),
@ -98,10 +111,8 @@ module.exports = grammar({
token.immediate('"""'),
),
escape_sequence: $ =>
token.immediate(
seq("\\", choice(/[btnfr"\\]/, /u[0-9a-fA-F]{4}/, /U[0-9a-fA-F]{8}/)),
),
_escape_line_ending: $ => token.immediate(seq("\\", /\r?\n/)),
token.immediate(/\\([btnfr"\\]|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/),
_escape_line_ending: $ => token.immediate(seq(/\\/, newline)),
_literal_string: $ =>
seq(
"'",
@ -137,14 +148,13 @@ module.exports = grammar({
float: $ =>
choice(
seq(
decimal_integer,
choice(
seq(
token.immediate(float_fractional_part),
optional(token.immediate(float_exponent_part)),
token(
seq(
decimal_integer,
choice(
float_fractional_part,
seq(optional(float_fractional_part), float_exponent_part),
),
token.immediate(float_exponent_part),
),
),
/[+-]?(inf|nan)/,
@ -153,29 +163,22 @@ module.exports = grammar({
boolean: $ => /true|false/,
offset_date_time: $ =>
concatRegex(
rfc3339_date,
rfc3339_delimiter,
rfc3339_time,
rfc3339_offset,
),
token(seq(rfc3339_date, rfc3339_delimiter, rfc3339_time, rfc3339_offset)),
local_date_time: $ =>
concatRegex(rfc3339_date, rfc3339_delimiter, rfc3339_time),
token(seq(rfc3339_date, rfc3339_delimiter, rfc3339_time)),
local_date: $ => rfc3339_date,
local_time: $ => rfc3339_time,
array: $ =>
seq(
"[",
repeat($._newline),
repeat(newline),
optional(
seq(
$._inline_value,
repeat($._newline),
repeat(
seq(",", repeat($._newline), $._inline_value, repeat($._newline)),
),
optional(seq(",", repeat($._newline))),
repeat(newline),
repeat(seq(",", repeat(newline), $._inline_value, repeat(newline))),
optional(seq(",", repeat(newline))),
),
),
"]",

284
src/grammar.json generated
View file

@ -1,38 +1,47 @@
{
"name": "toml",
"rules": {
"file": {
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "table_array"
},
{
"type": "SYMBOL",
"name": "_newline"
"document": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
]
}
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "table_array_element"
}
]
}
}
]
},
"comment": {
"type": "PATTERN",
"value": "#.*"
},
"_newline": {
"type": "PATTERN",
"value": "(\\r?\\n)+"
},
"table": {
"type": "SEQ",
"members": [
@ -60,10 +69,26 @@
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
}
]
},
"table_array": {
"table_array_element": {
"type": "SEQ",
"members": [
{
@ -90,6 +115,22 @@
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
}
]
},
@ -325,7 +366,7 @@
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "(\\r?\\n)+"
"value": "\\r?\\n"
}
},
{
@ -356,30 +397,8 @@
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[btnfr\"\\\\]"
},
{
"type": "PATTERN",
"value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "U[0-9a-fA-F]{8}"
}
]
}
]
"type": "PATTERN",
"value": "\\\\([btnfr\"\\\\]|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})"
}
},
"_escape_line_ending": {
@ -388,8 +407,8 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
"type": "PATTERN",
"value": "\\\\"
},
{
"type": "PATTERN",
@ -465,7 +484,7 @@
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "(\\r?\\n)+"
"value": "\\r?\\n"
}
}
]
@ -505,52 +524,55 @@
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[+-]?(0|[1-9](_?[0-9])*)"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[.][0-9](_?[0-9])*"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "([eE])([+-]?(0|[1-9](_?[0-9])*))"
}
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[+-]?(0|[1-9](_?[0-9])*)"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "([eE])([+-]?(0|[1-9](_?[0-9])*))"
"value": "[.][0-9](_?[0-9])*"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[.][0-9](_?[0-9])*"
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[eE]"
},
{
"type": "PATTERN",
"value": "[+-]?(0|[1-9](_?[0-9])*)"
}
]
}
]
}
}
]
}
]
]
}
]
}
},
{
"type": "PATTERN",
@ -563,12 +585,48 @@
"value": "true|false"
},
"offset_date_time": {
"type": "PATTERN",
"value": "(([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))([ tT])(([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?)(([zZ])|([+-]([01][0-9]|2[0-3]):[0-5][0-9]))"
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
},
{
"type": "PATTERN",
"value": "[ tT]"
},
{
"type": "PATTERN",
"value": "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?"
},
{
"type": "PATTERN",
"value": "([zZ])|([+-]([01][0-9]|2[0-3]):[0-5][0-9])"
}
]
}
},
"local_date_time": {
"type": "PATTERN",
"value": "(([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))([ tT])(([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?)"
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
},
{
"type": "PATTERN",
"value": "[ tT]"
},
{
"type": "PATTERN",
"value": "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?"
}
]
}
},
"local_date": {
"type": "PATTERN",
@ -588,8 +646,8 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
@ -605,8 +663,8 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
@ -621,8 +679,8 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
@ -632,8 +690,8 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PATTERN",
"value": "\\r?\\n"
}
}
]
@ -652,8 +710,8 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PATTERN",
"value": "\\r?\\n"
}
}
]

52
src/node-types.json generated
View file

@ -51,26 +51,7 @@
}
},
{
"type": "dotted_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "dotted_key",
"named": true
},
{
"type": "key",
"named": true
}
]
}
},
{
"type": "file",
"type": "document",
"named": true,
"fields": {},
"children": {
@ -86,7 +67,26 @@
"named": true
},
{
"type": "table_array",
"type": "table_array_element",
"named": true
}
]
}
},
{
"type": "dotted_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "dotted_key",
"named": true
},
{
"type": "key",
"named": true
}
]
@ -221,12 +221,16 @@
{
"type": "key",
"named": true
},
{
"type": "pair",
"named": true
}
]
}
},
{
"type": "table_array",
"type": "table_array_element",
"named": true,
"fields": {},
"children": {
@ -240,6 +244,10 @@
{
"type": "key",
"named": true
},
{
"type": "pair",
"named": true
}
]
}

3962
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -14,21 +14,19 @@ bool tree_sitter_toml_external_scanner_scan(
TSLexer *lexer,
const bool *valid_symbols
) {
lexer->result_symbol = LINE_ENDING_OR_EOF;
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') {
lexer->advance(lexer, true);
}
if (lexer->lookahead == 0 || lexer->lookahead == '\n') {
lexer->result_symbol = LINE_ENDING_OR_EOF;
lexer->mark_end(lexer);
return true;
}
if (lexer->lookahead == '\r') {
lexer->mark_end(lexer);
lexer->advance(lexer, false);
lexer->advance(lexer, true);
if (lexer->lookahead == '\n') {
lexer->result_symbol = LINE_ENDING_OR_EOF;
return true;
}
}