feat: flatten table/table-array structure (#2)
Input: ```toml [table] key = "value" ``` Output: ```sh # before (root (table (key) (pair (key) (string))) # after (root (table (key)) (pair (key) (string))) ```
This commit is contained in:
parent
43595130ac
commit
a3812033af
|
@ -45,9 +45,11 @@ invalid_both = 1 .0 e 2
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(ERROR
|
(root
|
||||||
(dotted_key
|
(ERROR
|
||||||
(key) (ERROR) (key)
|
(dotted_key
|
||||||
|
(key) (ERROR) (key)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,8 +62,10 @@ invalid2 = 1979-05-27 T 07:32:00 Z
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(ERROR
|
(root
|
||||||
(key) (ERROR) (local_time) (local_time)
|
(ERROR
|
||||||
|
(key) (ERROR) (local_time) (local_time)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -125,13 +129,13 @@ key = {
|
||||||
(pair
|
(pair
|
||||||
(key)
|
(key)
|
||||||
(inline_table
|
(inline_table
|
||||||
(MISSING "}")
|
(ERROR)
|
||||||
|
(pair
|
||||||
|
(key) (boolean)
|
||||||
|
)
|
||||||
|
(ERROR)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(pair
|
|
||||||
(key) (boolean)
|
|
||||||
)
|
|
||||||
(ERROR)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
@ -154,9 +158,96 @@ key
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(ERROR
|
(root
|
||||||
(ERROR
|
(ERROR
|
||||||
|
(key) (key)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
VALID - table - empty content separated by comments
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
[table]
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(root
|
||||||
|
(table
|
||||||
(key)
|
(key)
|
||||||
)
|
)
|
||||||
(key)
|
(comment)
|
||||||
|
)
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
VALID - array of tables - empty content separated by comments
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
[[array-table]]
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(root
|
||||||
|
(table_array
|
||||||
|
(key)
|
||||||
|
)
|
||||||
|
(comment)
|
||||||
|
)
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
VALID - table - two pairs separated by comments
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
[table]
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
b = 2
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(root
|
||||||
|
(table
|
||||||
|
(key)
|
||||||
|
)
|
||||||
|
(pair
|
||||||
|
(key) (integer)
|
||||||
|
)
|
||||||
|
(comment)
|
||||||
|
(pair
|
||||||
|
(key) (integer)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
VALID - array of tables - two pairs separated by comments
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
[[array-table]]
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
b = 2
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(root
|
||||||
|
(table_array
|
||||||
|
(key)
|
||||||
|
)
|
||||||
|
(pair
|
||||||
|
(key) (integer)
|
||||||
|
)
|
||||||
|
(comment)
|
||||||
|
(pair
|
||||||
|
(key) (integer)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
158
corpus/spec.txt
158
corpus/spec.txt
|
@ -37,12 +37,8 @@ key = # INVALID
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(root
|
(root
|
||||||
(pair
|
(ERROR
|
||||||
(key)
|
(key) (comment)
|
||||||
(comment)
|
|
||||||
(integer
|
|
||||||
(MISSING "integer_token1")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -782,21 +778,21 @@ key2 = 456
|
||||||
(root
|
(root
|
||||||
(table
|
(table
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
(table
|
(table
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -814,12 +810,12 @@ type.name = "pug"
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(dotted_key
|
(pair
|
||||||
(key) (key)
|
(dotted_key
|
||||||
)
|
(key) (key)
|
||||||
(string)
|
|
||||||
)
|
)
|
||||||
|
(string)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -920,15 +916,15 @@ c = 2
|
||||||
(comment)
|
(comment)
|
||||||
(table
|
(table
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
(table
|
(table
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -950,17 +946,17 @@ c = 2
|
||||||
(comment)
|
(comment)
|
||||||
(table
|
(table
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
(table
|
(table
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1030,27 +1026,27 @@ color = "gray"
|
||||||
(root
|
(root
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
(pair
|
)
|
||||||
(key) (integer)
|
(pair
|
||||||
)
|
(key) (integer)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1082,50 +1078,50 @@ VALID - array of tables - nested arrays of tables
|
||||||
(root
|
(root
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table
|
(table
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1171,25 +1167,25 @@ VALID - array of tables - append to table (semantically INVALID)
|
||||||
(comment)
|
(comment)
|
||||||
(table_array
|
(table_array
|
||||||
(key)
|
(key)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
(table_array
|
(table_array
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
|
||||||
(key) (string)
|
|
||||||
)
|
|
||||||
(comment)
|
|
||||||
)
|
)
|
||||||
|
(pair
|
||||||
|
(key) (string)
|
||||||
|
)
|
||||||
|
(comment)
|
||||||
(table
|
(table
|
||||||
(dotted_key
|
(dotted_key
|
||||||
(key) (key)
|
(key) (key)
|
||||||
)
|
)
|
||||||
(pair
|
)
|
||||||
(key) (string)
|
(pair
|
||||||
)
|
(key) (string)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
51
grammar.js
51
grammar.js
|
@ -23,38 +23,24 @@ const rfc3339_offset = /([zZ])|([+-]([01][0-9]|2[0-3]):[0-5][0-9])/;
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
name: "toml",
|
name: "toml",
|
||||||
|
|
||||||
externals: $ => [$._eof],
|
externals: $ => [$._line_ending_or_eof],
|
||||||
|
|
||||||
extras: $ => [$.comment, /[ \t]/],
|
extras: $ => [$.comment, /[ \t]/],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
root: $ =>
|
root: $ => repeat(choice($.pair, $.table, $.table_array, $._newline)),
|
||||||
seq(
|
|
||||||
repeat($._newline),
|
|
||||||
choice(
|
|
||||||
$._eof,
|
|
||||||
seq(
|
|
||||||
choice($.pair, $._loose_pair, $._pairs, $.table, $.table_array),
|
|
||||||
repeat(choice($.table, $.table_array))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
comment: $ => /#.*/,
|
comment: $ => /#.*/,
|
||||||
_newline: $ => newline,
|
_newline: $ => newline,
|
||||||
_newline_or_eof: $ => choice($._newline, $._eof),
|
|
||||||
|
|
||||||
...table_like("table", "[", "]"),
|
table: $ =>
|
||||||
...table_like("table_array", "[[", "]]"),
|
seq("[", choice($.dotted_key, $.key), "]", $._line_ending_or_eof),
|
||||||
|
|
||||||
pair: $ => seq($._inline_pair, $._newline_or_eof),
|
table_array: $ =>
|
||||||
|
seq("[[", choice($.dotted_key, $.key), "]]", $._line_ending_or_eof),
|
||||||
|
|
||||||
|
pair: $ => seq($._inline_pair, $._line_ending_or_eof),
|
||||||
_inline_pair: $ => seq(choice($.dotted_key, $.key), "=", $._inline_value),
|
_inline_pair: $ => seq(choice($.dotted_key, $.key), "=", $._inline_value),
|
||||||
_loose_pair: $ => seq(choice($._loose_pair, $.pair), $._newline),
|
|
||||||
_pairs: $ =>
|
|
||||||
seq(
|
|
||||||
choice($.pair, $._loose_pair, $._pairs),
|
|
||||||
choice($.pair, $._loose_pair)
|
|
||||||
),
|
|
||||||
|
|
||||||
key: $ => choice($._bare_key, $._quoted_key),
|
key: $ => choice($._bare_key, $._quoted_key),
|
||||||
dotted_key: $ => seq(choice($.dotted_key, $.key), ".", $.key),
|
dotted_key: $ => seq(choice($.dotted_key, $.key), ".", $.key),
|
||||||
|
@ -212,24 +198,3 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function table_like(name, header_start, header_end) {
|
|
||||||
const header_name = `_${name}_header`;
|
|
||||||
const loose_header_name = `_loose_${name}_header`;
|
|
||||||
return {
|
|
||||||
[name]: $ =>
|
|
||||||
seq(
|
|
||||||
choice($[header_name], $[loose_header_name]),
|
|
||||||
optional(choice($.pair, $._loose_pair, $._pairs))
|
|
||||||
),
|
|
||||||
[header_name]: $ =>
|
|
||||||
seq(
|
|
||||||
header_start,
|
|
||||||
choice($.dotted_key, $.key),
|
|
||||||
header_end,
|
|
||||||
$._newline_or_eof
|
|
||||||
),
|
|
||||||
[loose_header_name]: $ =>
|
|
||||||
seq(choice($[loose_header_name], $[header_name]), $._newline),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
289
src/grammar.json
generated
289
src/grammar.json
generated
|
@ -2,71 +2,28 @@
|
||||||
"name": "toml",
|
"name": "toml",
|
||||||
"rules": {
|
"rules": {
|
||||||
"root": {
|
"root": {
|
||||||
"type": "SEQ",
|
"type": "REPEAT",
|
||||||
"members": [
|
"content": {
|
||||||
{
|
"type": "CHOICE",
|
||||||
"type": "REPEAT",
|
"members": [
|
||||||
"content": {
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "pair"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "table"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "table_array"
|
||||||
|
},
|
||||||
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_newline"
|
"name": "_newline"
|
||||||
}
|
}
|
||||||
},
|
]
|
||||||
{
|
}
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_eof"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_pairs"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "table"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "table_array"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "REPEAT",
|
|
||||||
"content": {
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "table"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "table_array"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
|
@ -76,63 +33,7 @@
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "(\\r?\\n)+"
|
"value": "(\\r?\\n)+"
|
||||||
},
|
},
|
||||||
"_newline_or_eof": {
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_newline"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_eof"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"table": {
|
"table": {
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_table_header"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_table_header"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_pairs"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_table_header": {
|
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -158,76 +59,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_newline_or_eof"
|
"name": "_line_ending_or_eof"
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_loose_table_header": {
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_table_header"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_table_header"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_newline"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"table_array": {
|
"table_array": {
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_table_array_header"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_table_array_header"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_pairs"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_table_array_header": {
|
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -253,29 +89,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_newline_or_eof"
|
"name": "_line_ending_or_eof"
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_loose_table_array_header": {
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_table_array_header"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_table_array_header"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_newline"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -288,7 +102,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_newline_or_eof"
|
"name": "_line_ending_or_eof"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -318,63 +132,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_loose_pair": {
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_newline"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_pairs": {
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_pairs"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "pair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_loose_pair"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"key": {
|
"key": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -1035,7 +792,7 @@
|
||||||
"externals": [
|
"externals": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_eof"
|
"name": "_line_ending_or_eof"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"inline": [],
|
"inline": [],
|
||||||
|
|
8
src/node-types.json
generated
8
src/node-types.json
generated
|
@ -236,10 +236,6 @@
|
||||||
{
|
{
|
||||||
"type": "key",
|
"type": "key",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "pair",
|
|
||||||
"named": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -259,10 +255,6 @@
|
||||||
{
|
{
|
||||||
"type": "key",
|
"type": "key",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "pair",
|
|
||||||
"named": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
4227
src/parser.c
generated
4227
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
||||||
#include <tree_sitter/parser.h>
|
#include <tree_sitter/parser.h>
|
||||||
|
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
EOF
|
LINE_ENDING_OR_EOF
|
||||||
};
|
};
|
||||||
|
|
||||||
void *tree_sitter_toml_external_scanner_create() { return NULL; }
|
void *tree_sitter_toml_external_scanner_create() { return NULL; }
|
||||||
|
@ -15,10 +15,20 @@ bool tree_sitter_toml_external_scanner_scan(
|
||||||
TSLexer *lexer,
|
TSLexer *lexer,
|
||||||
const bool *valid_symbols
|
const bool *valid_symbols
|
||||||
) {
|
) {
|
||||||
if (lexer->lookahead != 0) {
|
if (lexer->lookahead == 0 || lexer->lookahead == '\n') {
|
||||||
return false;
|
lexer->result_symbol = LINE_ENDING_OR_EOF;
|
||||||
|
lexer->mark_end(lexer);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
lexer->result_symbol = EOF;
|
|
||||||
lexer->mark_end(lexer);
|
if (lexer->lookahead == '\r') {
|
||||||
return true;
|
lexer->mark_end(lexer);
|
||||||
|
lexer->advance(lexer, false);
|
||||||
|
if (lexer->lookahead == '\n') {
|
||||||
|
lexer->result_symbol = LINE_ENDING_OR_EOF;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue