feat: rename root with file

This commit is contained in:
Ika 2019-08-20 15:01:47 +08:00
parent a3812033af
commit a0cd384b98
6 changed files with 97 additions and 97 deletions

View file

@ -4,7 +4,7 @@ VALID - empty file
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root) (file)
================================================================================ ================================================================================
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
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (ERROR) (boolean) (key) (ERROR) (boolean)
) )
@ -45,7 +45,7 @@ invalid_both = 1 .0 e 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(ERROR (ERROR
(dotted_key (dotted_key
(key) (ERROR) (key) (key) (ERROR) (key)
@ -62,7 +62,7 @@ invalid2 = 1979-05-27 T 07:32:00 Z
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(ERROR (ERROR
(key) (ERROR) (local_time) (local_time) (key) (ERROR) (local_time) (local_time)
) )
@ -77,7 +77,7 @@ invalid2 = 1979-05-27 T 07:32:00
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (ERROR) (local_time) (key) (ERROR) (local_time)
) )
@ -106,7 +106,7 @@ key
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(key) (ERROR) (key) (ERROR)
) )
@ -125,7 +125,7 @@ key = {
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (key)
(inline_table (inline_table
@ -158,7 +158,7 @@ key
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(ERROR (ERROR
(key) (key) (key) (key)
) )
@ -174,7 +174,7 @@ VALID - table - empty content separated by comments
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(key) (key)
) )
@ -191,7 +191,7 @@ VALID - array of tables - empty content separated by comments
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table_array (table_array
(key) (key)
) )
@ -212,7 +212,7 @@ b = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(key) (key)
) )
@ -239,7 +239,7 @@ b = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table_array (table_array
(key) (key)
) )

View file

@ -7,7 +7,7 @@ key = "value" # This is a comment at the end of a line
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (string) (comment) (key) (string) (comment)
@ -22,7 +22,7 @@ key = "value"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -36,7 +36,7 @@ key = # INVALID
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(ERROR (ERROR
(key) (comment) (key) (comment)
) )
@ -53,7 +53,7 @@ bare-key = "value"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -80,7 +80,7 @@ VALID - keys - quoted keys
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -108,7 +108,7 @@ INVALID - keys - empty bare key
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key (key
(MISSING _bare_key) (MISSING _bare_key)
@ -135,7 +135,7 @@ site."google.com" = true
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -169,7 +169,7 @@ name = "Pradyun"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (string) (key) (string)
@ -188,7 +188,7 @@ a.d = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(dotted_key (dotted_key
(dotted_key (dotted_key
@ -216,7 +216,7 @@ a.b.c = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(dotted_key (dotted_key
@ -243,7 +243,7 @@ str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (key)
(string (string
@ -262,7 +262,7 @@ Violets are blue"""
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -290,7 +290,7 @@ str3 = """\
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (string) (key) (string)
@ -321,7 +321,7 @@ regex = '<\i\c*\s*>'
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (string) (key) (string)
@ -351,7 +351,7 @@ trimmed in raw strings.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (string) (key) (string)
) )
@ -371,7 +371,7 @@ int4 = -17
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (integer) (key) (integer)
) )
@ -396,7 +396,7 @@ int7 = 1_2_3_4_5 # VALID but discouraged
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (integer) (key) (integer)
) )
@ -426,7 +426,7 @@ bin1 = 0b11010110
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (integer) (key) (integer)
@ -469,7 +469,7 @@ flt7 = 6.626e-34
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (float) (key) (float)
@ -504,7 +504,7 @@ flt8 = 9_224_617.445_991_228_313
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (float) (key) (float)
) )
@ -526,7 +526,7 @@ sf6 = -nan # valid, actual encoding is implementation specific
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (float) (comment) (key) (float) (comment)
@ -558,7 +558,7 @@ bool2 = false
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (boolean) (key) (boolean)
) )
@ -577,7 +577,7 @@ odt3 = 1979-05-27T00:32:00.999999-07:00
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (offset_date_time) (key) (offset_date_time)
) )
@ -597,7 +597,7 @@ odt4 = 1979-05-27 07:32:00Z
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (offset_date_time) (key) (offset_date_time)
) )
@ -612,7 +612,7 @@ ldt2 = 1979-05-27T00:32:00.999999
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (local_date_time) (key) (local_date_time)
) )
@ -629,7 +629,7 @@ ld1 = 1979-05-27
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (local_date) (key) (local_date)
) )
@ -644,7 +644,7 @@ lt2 = 00:32:00.999999
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (local_time) (key) (local_time)
) )
@ -667,7 +667,7 @@ arr6 = [ 1, 2.0 ] # INVALID
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (key)
(array (array
@ -732,7 +732,7 @@ arr8 = [
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (key)
(array (array
@ -755,7 +755,7 @@ VALID - table - header
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(key) (key)
) )
@ -775,7 +775,7 @@ key2 = 456
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(key) (key)
) )
@ -805,7 +805,7 @@ type.name = "pug"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(dotted_key (dotted_key
(key) (key) (key) (key)
@ -830,7 +830,7 @@ VALID - table- header with whitespaces
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table (table
(dotted_key (dotted_key
(dotted_key (dotted_key
@ -880,7 +880,7 @@ VALID - table - directly defined nested header key
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(comment) (comment)
(comment) (comment)
@ -912,7 +912,7 @@ c = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(table (table
(key) (key)
@ -942,7 +942,7 @@ c = 2
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(table (table
(key) (key)
@ -970,7 +970,7 @@ animal = { type.name = "pug" }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(pair (pair
(key) (key)
(inline_table (inline_table
@ -1023,7 +1023,7 @@ color = "gray"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table_array (table_array
(key) (key)
) )
@ -1075,7 +1075,7 @@ VALID - array of tables - nested arrays of tables
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(table_array (table_array
(key) (key)
) )
@ -1136,7 +1136,7 @@ fruit = []
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(pair (pair
(key) (array) (key) (array)
@ -1163,7 +1163,7 @@ VALID - array of tables - append to table (semantically INVALID)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(root (file
(comment) (comment)
(table_array (table_array
(key) (key)

View file

@ -28,7 +28,7 @@ module.exports = grammar({
extras: $ => [$.comment, /[ \t]/], extras: $ => [$.comment, /[ \t]/],
rules: { rules: {
root: $ => repeat(choice($.pair, $.table, $.table_array, $._newline)), file: $ => repeat(choice($.pair, $.table, $.table_array, $._newline)),
comment: $ => /#.*/, comment: $ => /#.*/,
_newline: $ => newline, _newline: $ => newline,

2
src/grammar.json generated
View file

@ -1,7 +1,7 @@
{ {
"name": "toml", "name": "toml",
"rules": { "rules": {
"root": { "file": {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",

46
src/node-types.json generated
View file

@ -69,6 +69,29 @@
] ]
} }
}, },
{
"type": "file",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "pair",
"named": true
},
{
"type": "table",
"named": true
},
{
"type": "table_array",
"named": true
}
]
}
},
{ {
"type": "float", "type": "float",
"named": true, "named": true,
@ -183,29 +206,6 @@
] ]
} }
}, },
{
"type": "root",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "pair",
"named": true
},
{
"type": "table",
"named": true
},
{
"type": "table_array",
"named": true
}
]
}
},
{ {
"type": "string", "type": "string",
"named": true, "named": true,

38
src/parser.c generated
View file

@ -56,7 +56,7 @@ enum {
anon_sym_LBRACE = 39, anon_sym_LBRACE = 39,
anon_sym_RBRACE = 40, anon_sym_RBRACE = 40,
sym__line_ending_or_eof = 41, sym__line_ending_or_eof = 41,
sym_root = 42, sym_file = 42,
sym_table = 43, sym_table = 43,
sym_table_array = 44, sym_table_array = 44,
sym_pair = 45, sym_pair = 45,
@ -77,7 +77,7 @@ enum {
sym_local_date = 60, sym_local_date = 60,
sym_array = 61, sym_array = 61,
sym_inline_table = 62, sym_inline_table = 62,
aux_sym_root_repeat1 = 63, aux_sym_file_repeat1 = 63,
aux_sym__basic_string_repeat1 = 64, aux_sym__basic_string_repeat1 = 64,
aux_sym__multiline_basic_string_repeat1 = 65, aux_sym__multiline_basic_string_repeat1 = 65,
aux_sym__multiline_literal_string_repeat1 = 66, aux_sym__multiline_literal_string_repeat1 = 66,
@ -129,7 +129,7 @@ static const char *ts_symbol_names[] = {
[anon_sym_LBRACE] = "{", [anon_sym_LBRACE] = "{",
[anon_sym_RBRACE] = "}", [anon_sym_RBRACE] = "}",
[sym__line_ending_or_eof] = "_line_ending_or_eof", [sym__line_ending_or_eof] = "_line_ending_or_eof",
[sym_root] = "root", [sym_file] = "file",
[sym_table] = "table", [sym_table] = "table",
[sym_table_array] = "table_array", [sym_table_array] = "table_array",
[sym_pair] = "pair", [sym_pair] = "pair",
@ -150,7 +150,7 @@ static const char *ts_symbol_names[] = {
[sym_local_date] = "local_date", [sym_local_date] = "local_date",
[sym_array] = "array", [sym_array] = "array",
[sym_inline_table] = "inline_table", [sym_inline_table] = "inline_table",
[aux_sym_root_repeat1] = "root_repeat1", [aux_sym_file_repeat1] = "file_repeat1",
[aux_sym__basic_string_repeat1] = "_basic_string_repeat1", [aux_sym__basic_string_repeat1] = "_basic_string_repeat1",
[aux_sym__multiline_basic_string_repeat1] = "_multiline_basic_string_repeat1", [aux_sym__multiline_basic_string_repeat1] = "_multiline_basic_string_repeat1",
[aux_sym__multiline_literal_string_repeat1] = "_multiline_literal_string_repeat1", [aux_sym__multiline_literal_string_repeat1] = "_multiline_literal_string_repeat1",
@ -328,7 +328,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = false, .visible = false,
.named = true, .named = true,
}, },
[sym_root] = { [sym_file] = {
.visible = true, .visible = true,
.named = true, .named = true,
}, },
@ -412,7 +412,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = true, .visible = true,
.named = true, .named = true,
}, },
[aux_sym_root_repeat1] = { [aux_sym_file_repeat1] = {
.visible = false, .visible = false,
.named = false, .named = false,
}, },
@ -1908,10 +1908,10 @@ static uint16_t ts_parse_table[STATE_COUNT][SYMBOL_COUNT] = {
[sym_pair] = STATE(9), [sym_pair] = STATE(9),
[sym__inline_pair] = STATE(7), [sym__inline_pair] = STATE(7),
[sym__basic_string] = STATE(4), [sym__basic_string] = STATE(4),
[sym_root] = STATE(8), [sym_file] = STATE(8),
[sym_key] = STATE(10), [sym_key] = STATE(10),
[sym_dotted_key] = STATE(10), [sym_dotted_key] = STATE(10),
[aux_sym_root_repeat1] = STATE(9), [aux_sym_file_repeat1] = STATE(9),
[sym__literal_string] = STATE(4), [sym__literal_string] = STATE(4),
[sym_table] = STATE(9), [sym_table] = STATE(9),
[sym_table_array] = STATE(9), [sym_table_array] = STATE(9),
@ -1977,7 +1977,7 @@ static uint16_t ts_parse_table[STATE_COUNT][SYMBOL_COUNT] = {
[sym_pair] = STATE(18), [sym_pair] = STATE(18),
[sym__inline_pair] = STATE(7), [sym__inline_pair] = STATE(7),
[sym__basic_string] = STATE(4), [sym__basic_string] = STATE(4),
[aux_sym_root_repeat1] = STATE(18), [aux_sym_file_repeat1] = STATE(18),
[sym_dotted_key] = STATE(10), [sym_dotted_key] = STATE(10),
[sym_key] = STATE(10), [sym_key] = STATE(10),
[sym__literal_string] = STATE(4), [sym__literal_string] = STATE(4),
@ -2049,7 +2049,7 @@ static uint16_t ts_parse_table[STATE_COUNT][SYMBOL_COUNT] = {
[sym_pair] = STATE(18), [sym_pair] = STATE(18),
[sym__inline_pair] = STATE(7), [sym__inline_pair] = STATE(7),
[sym__basic_string] = STATE(4), [sym__basic_string] = STATE(4),
[aux_sym_root_repeat1] = STATE(18), [aux_sym_file_repeat1] = STATE(18),
[sym_dotted_key] = STATE(10), [sym_dotted_key] = STATE(10),
[sym_key] = STATE(10), [sym_key] = STATE(10),
[sym__literal_string] = STATE(4), [sym__literal_string] = STATE(4),
@ -3648,7 +3648,7 @@ static TSParseActionEntry ts_parse_actions[] = {
[3] = {.count = 1, .reusable = true}, SHIFT_EXTRA(), [3] = {.count = 1, .reusable = true}, SHIFT_EXTRA(),
[5] = {.count = 1, .reusable = true}, SHIFT(2), [5] = {.count = 1, .reusable = true}, SHIFT(2),
[7] = {.count = 1, .reusable = true}, SHIFT(3), [7] = {.count = 1, .reusable = true}, SHIFT(3),
[9] = {.count = 1, .reusable = true}, REDUCE(sym_root, 0), [9] = {.count = 1, .reusable = true}, REDUCE(sym_file, 0),
[11] = {.count = 1, .reusable = true}, SHIFT(9), [11] = {.count = 1, .reusable = true}, SHIFT(9),
[13] = {.count = 1, .reusable = true}, SHIFT(4), [13] = {.count = 1, .reusable = true}, SHIFT(4),
[15] = {.count = 1, .reusable = false}, SHIFT(5), [15] = {.count = 1, .reusable = false}, SHIFT(5),
@ -3665,7 +3665,7 @@ static TSParseActionEntry ts_parse_actions[] = {
[37] = {.count = 1, .reusable = false}, SHIFT(16), [37] = {.count = 1, .reusable = false}, SHIFT(16),
[39] = {.count = 1, .reusable = true}, SHIFT(17), [39] = {.count = 1, .reusable = true}, SHIFT(17),
[41] = {.count = 1, .reusable = true}, ACCEPT_INPUT(), [41] = {.count = 1, .reusable = true}, ACCEPT_INPUT(),
[43] = {.count = 1, .reusable = true}, REDUCE(sym_root, 1), [43] = {.count = 1, .reusable = true}, REDUCE(sym_file, 1),
[45] = {.count = 1, .reusable = true}, SHIFT(18), [45] = {.count = 1, .reusable = true}, SHIFT(18),
[47] = {.count = 1, .reusable = true}, SHIFT(19), [47] = {.count = 1, .reusable = true}, SHIFT(19),
[49] = {.count = 1, .reusable = true}, SHIFT(20), [49] = {.count = 1, .reusable = true}, SHIFT(20),
@ -3680,13 +3680,13 @@ static TSParseActionEntry ts_parse_actions[] = {
[67] = {.count = 1, .reusable = true}, SHIFT(25), [67] = {.count = 1, .reusable = true}, SHIFT(25),
[69] = {.count = 1, .reusable = true}, REDUCE(sym_pair, 2), [69] = {.count = 1, .reusable = true}, REDUCE(sym_pair, 2),
[71] = {.count = 1, .reusable = false}, REDUCE(sym_pair, 2), [71] = {.count = 1, .reusable = false}, REDUCE(sym_pair, 2),
[73] = {.count = 2, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(2), [73] = {.count = 2, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(2),
[76] = {.count = 2, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(3), [76] = {.count = 2, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(3),
[79] = {.count = 1, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), [79] = {.count = 1, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2),
[81] = {.count = 2, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(18), [81] = {.count = 2, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(18),
[84] = {.count = 2, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(4), [84] = {.count = 2, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(4),
[87] = {.count = 2, .reusable = false}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(5), [87] = {.count = 2, .reusable = false}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(5),
[90] = {.count = 2, .reusable = true}, REDUCE(aux_sym_root_repeat1, 2), SHIFT_REPEAT(6), [90] = {.count = 2, .reusable = true}, REDUCE(aux_sym_file_repeat1, 2), SHIFT_REPEAT(6),
[93] = {.count = 1, .reusable = false}, SHIFT(158), [93] = {.count = 1, .reusable = false}, SHIFT(158),
[95] = {.count = 1, .reusable = true}, SHIFT(28), [95] = {.count = 1, .reusable = true}, SHIFT(28),
[97] = {.count = 1, .reusable = true}, SHIFT(26), [97] = {.count = 1, .reusable = true}, SHIFT(26),