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

View file

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

View file

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

284
src/grammar.json generated
View file

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

52
src/node-types.json generated
View file

@ -51,26 +51,7 @@
} }
}, },
{ {
"type": "dotted_key", "type": "document",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "dotted_key",
"named": true
},
{
"type": "key",
"named": true
}
]
}
},
{
"type": "file",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
@ -86,7 +67,26 @@
"named": true "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 "named": true
} }
] ]
@ -221,12 +221,16 @@
{ {
"type": "key", "type": "key",
"named": true "named": true
},
{
"type": "pair",
"named": true
} }
] ]
} }
}, },
{ {
"type": "table_array", "type": "table_array_element",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
@ -240,6 +244,10 @@
{ {
"type": "key", "type": "key",
"named": true "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, TSLexer *lexer,
const bool *valid_symbols const bool *valid_symbols
) { ) {
lexer->result_symbol = LINE_ENDING_OR_EOF;
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') { while (lexer->lookahead == ' ' || lexer->lookahead == '\t') {
lexer->advance(lexer, true); lexer->advance(lexer, true);
} }
if (lexer->lookahead == 0 || lexer->lookahead == '\n') { if (lexer->lookahead == 0 || lexer->lookahead == '\n') {
lexer->result_symbol = LINE_ENDING_OR_EOF;
lexer->mark_end(lexer);
return true; return true;
} }
if (lexer->lookahead == '\r') { if (lexer->lookahead == '\r') {
lexer->mark_end(lexer); lexer->advance(lexer, true);
lexer->advance(lexer, false);
if (lexer->lookahead == '\n') { if (lexer->lookahead == '\n') {
lexer->result_symbol = LINE_ENDING_OR_EOF;
return true; return true;
} }
} }