Make token for command name anonymous

This commit is contained in:
Uy Ha 2021-06-13 22:39:43 +02:00
parent c0b417d056
commit 5a730d2140
5 changed files with 66 additions and 93 deletions

View file

@ -10,12 +10,9 @@ endforeach()
(source_file (source_file
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach)
(arguments (argument (unquoted_argument))) (arguments (argument (unquoted_argument)))
) )
(endforeach_command (endforeach_command)
(endforeach)
)
) )
) )
@ -31,11 +28,9 @@ endforeach(var)
(source_file (source_file
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach)
(arguments (argument (unquoted_argument))) (arguments (argument (unquoted_argument)))
) )
(endforeach_command (endforeach_command
(endforeach)
(argument (unquoted_argument)) (argument (unquoted_argument))
) )
)) ))
@ -52,12 +47,9 @@ ENDFOREACH()
(source_file (source_file
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach)
(arguments (argument (unquoted_argument))) (arguments (argument (unquoted_argument)))
) )
(endforeach_command (endforeach_command)
(endforeach)
)
) )
) )
@ -73,11 +65,8 @@ endForEach()
(source_file (source_file
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach)
(arguments (argument (unquoted_argument))) (arguments (argument (unquoted_argument)))
) )
(endforeach_command (endforeach_command)
(endforeach)
)
) )
) )

View file

@ -39,9 +39,9 @@ module.exports = grammar({
arguments: ($) => seq($.argument, repeat($._seperated_arguments)), arguments: ($) => seq($.argument, repeat($._seperated_arguments)),
_seperated_arguments: ($) => prec.left(seq(repeat1($.seperation), optional($.argument))), _seperated_arguments: ($) => prec.left(seq(repeat1($.seperation), optional($.argument))),
foreach_command: ($) => seq($.foreach, "(", $.arguments, ")"), foreach_command: ($) => seq($._foreach, "(", $.arguments, ")"),
endforeach_command: ($) => endforeach_command: ($) =>
seq($.endforeach, "(", repeat($.seperation), optional($.argument), ")"), seq($._endforeach, "(", repeat($.seperation), optional($.argument), ")"),
foreach_loop: ($) => foreach_loop: ($) =>
seq($.foreach_command, repeat($._command_invocation), $.endforeach_command), seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
normal_command: ($) => seq($.identifier, "(", repeat($.seperation), optional($.arguments), ")"), normal_command: ($) => seq($.identifier, "(", repeat($.seperation), optional($.arguments), ")"),
@ -57,7 +57,7 @@ function iregex(s) {
} }
function commandName(name) { function commandName(name) {
return { [name]: ($) => iregex(name) }; return { ['_' + name]: ($) => iregex(name) };
} }
function commands(...names) { function commands(...names) {

View file

@ -33,11 +33,11 @@
"type": "PATTERN", "type": "PATTERN",
"value": "\\n+" "value": "\\n+"
}, },
"foreach": { "_foreach": {
"type": "PATTERN", "type": "PATTERN",
"value": "[fF][oO][rR][eE][aA][cC][hH]" "value": "[fF][oO][rR][eE][aA][cC][hH]"
}, },
"endforeach": { "_endforeach": {
"type": "PATTERN", "type": "PATTERN",
"value": "[eE][nN][dD][fF][oO][rR][eE][aA][cC][hH]" "value": "[eE][nN][dD][fF][oO][rR][eE][aA][cC][hH]"
}, },
@ -395,7 +395,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "foreach" "name": "_foreach"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -416,7 +416,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "endforeach" "name": "_endforeach"
}, },
{ {
"type": "STRING", "type": "STRING",

View file

@ -82,16 +82,12 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "argument", "type": "argument",
"named": true "named": true
}, },
{
"type": "endforeach",
"named": true
},
{ {
"type": "seperation", "type": "seperation",
"named": true "named": true
@ -124,16 +120,12 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "arguments", "type": "arguments",
"named": true "named": true
},
{
"type": "foreach",
"named": true
} }
] ]
} }
@ -403,14 +395,6 @@
"type": "]", "type": "]",
"named": false "named": false
}, },
{
"type": "endforeach",
"named": true
},
{
"type": "foreach",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true

View file

@ -19,8 +19,8 @@
enum { enum {
sym_space = 1, sym_space = 1,
sym_newline = 2, sym_newline = 2,
sym_foreach = 3, sym__foreach = 3,
sym_endforeach = 4, sym__endforeach = 4,
sym_identifier = 5, sym_identifier = 5,
sym__escape_identity = 6, sym__escape_identity = 6,
anon_sym_BSLASHt = 7, anon_sym_BSLASHt = 7,
@ -81,8 +81,8 @@ static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end", [ts_builtin_sym_end] = "end",
[sym_space] = "space", [sym_space] = "space",
[sym_newline] = "newline", [sym_newline] = "newline",
[sym_foreach] = "foreach", [sym__foreach] = "_foreach",
[sym_endforeach] = "endforeach", [sym__endforeach] = "_endforeach",
[sym_identifier] = "identifier", [sym_identifier] = "identifier",
[sym__escape_identity] = "_escape_identity", [sym__escape_identity] = "_escape_identity",
[anon_sym_BSLASHt] = "\\t", [anon_sym_BSLASHt] = "\\t",
@ -143,8 +143,8 @@ static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end, [ts_builtin_sym_end] = ts_builtin_sym_end,
[sym_space] = sym_space, [sym_space] = sym_space,
[sym_newline] = sym_newline, [sym_newline] = sym_newline,
[sym_foreach] = sym_foreach, [sym__foreach] = sym__foreach,
[sym_endforeach] = sym_endforeach, [sym__endforeach] = sym__endforeach,
[sym_identifier] = sym_identifier, [sym_identifier] = sym_identifier,
[sym__escape_identity] = sym__escape_identity, [sym__escape_identity] = sym__escape_identity,
[anon_sym_BSLASHt] = anon_sym_BSLASHt, [anon_sym_BSLASHt] = anon_sym_BSLASHt,
@ -214,12 +214,12 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = true, .visible = true,
.named = true, .named = true,
}, },
[sym_foreach] = { [sym__foreach] = {
.visible = true, .visible = false,
.named = true, .named = true,
}, },
[sym_endforeach] = { [sym__endforeach] = {
.visible = true, .visible = false,
.named = true, .named = true,
}, },
[sym_identifier] = { [sym_identifier] = {
@ -690,14 +690,14 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (lookahead == '\n') ADVANCE(29); if (lookahead == '\n') ADVANCE(29);
END_STATE(); END_STATE();
case 30: case 30:
ACCEPT_TOKEN(sym_foreach); ACCEPT_TOKEN(sym__foreach);
if (('0' <= lookahead && lookahead <= '9') || if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' || lookahead == '_' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(47); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(47);
END_STATE(); END_STATE();
case 31: case 31:
ACCEPT_TOKEN(sym_endforeach); ACCEPT_TOKEN(sym__endforeach);
if (('0' <= lookahead && lookahead <= '9') || if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' || lookahead == '_' ||
@ -1181,7 +1181,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym__command_invocation] = STATE(57), [sym__command_invocation] = STATE(57),
[aux_sym_source_file_repeat1] = STATE(57), [aux_sym_source_file_repeat1] = STATE(57),
[ts_builtin_sym_end] = ACTIONS(3), [ts_builtin_sym_end] = ACTIONS(3),
[sym_foreach] = ACTIONS(5), [sym__foreach] = ACTIONS(5),
[sym_identifier] = ACTIONS(7), [sym_identifier] = ACTIONS(7),
}, },
[2] = { [2] = {
@ -2265,9 +2265,9 @@ static const uint16_t ts_small_parse_table[] = {
sym__escape_semicolon, sym__escape_semicolon,
[1206] = 6, [1206] = 6,
ACTIONS(5), 1, ACTIONS(5), 1,
sym_foreach, sym__foreach,
ACTIONS(173), 1, ACTIONS(173), 1,
sym_endforeach, sym__endforeach,
ACTIONS(175), 1, ACTIONS(175), 1,
sym_identifier, sym_identifier,
STATE(51), 1, STATE(51), 1,
@ -2281,11 +2281,11 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym_source_file_repeat1, aux_sym_source_file_repeat1,
[1228] = 6, [1228] = 6,
ACTIONS(5), 1, ACTIONS(5), 1,
sym_foreach, sym__foreach,
ACTIONS(175), 1, ACTIONS(175), 1,
sym_identifier, sym_identifier,
ACTIONS(177), 1, ACTIONS(177), 1,
sym_endforeach, sym__endforeach,
STATE(51), 1, STATE(51), 1,
sym_foreach_command, sym_foreach_command,
STATE(76), 1, STATE(76), 1,
@ -2297,9 +2297,9 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym_source_file_repeat1, aux_sym_source_file_repeat1,
[1250] = 6, [1250] = 6,
ACTIONS(5), 1, ACTIONS(5), 1,
sym_foreach, sym__foreach,
ACTIONS(173), 1, ACTIONS(173), 1,
sym_endforeach, sym__endforeach,
ACTIONS(175), 1, ACTIONS(175), 1,
sym_identifier, sym_identifier,
STATE(51), 1, STATE(51), 1,
@ -2313,11 +2313,11 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym_source_file_repeat1, aux_sym_source_file_repeat1,
[1272] = 6, [1272] = 6,
ACTIONS(5), 1, ACTIONS(5), 1,
sym_foreach, sym__foreach,
ACTIONS(175), 1, ACTIONS(175), 1,
sym_identifier, sym_identifier,
ACTIONS(177), 1, ACTIONS(177), 1,
sym_endforeach, sym__endforeach,
STATE(51), 1, STATE(51), 1,
sym_foreach_command, sym_foreach_command,
STATE(83), 1, STATE(83), 1,
@ -2346,7 +2346,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(181), 1, ACTIONS(181), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(183), 1, ACTIONS(183), 1,
sym_foreach, sym__foreach,
ACTIONS(186), 1, ACTIONS(186), 1,
sym_identifier, sym_identifier,
STATE(52), 1, STATE(52), 1,
@ -2358,9 +2358,9 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym_source_file_repeat1, aux_sym_source_file_repeat1,
[1334] = 5, [1334] = 5,
ACTIONS(183), 1, ACTIONS(183), 1,
sym_foreach, sym__foreach,
ACTIONS(189), 1, ACTIONS(189), 1,
sym_endforeach, sym__endforeach,
ACTIONS(191), 1, ACTIONS(191), 1,
sym_identifier, sym_identifier,
STATE(51), 1, STATE(51), 1,
@ -2372,7 +2372,7 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym_source_file_repeat1, aux_sym_source_file_repeat1,
[1353] = 5, [1353] = 5,
ACTIONS(5), 1, ACTIONS(5), 1,
sym_foreach, sym__foreach,
ACTIONS(7), 1, ACTIONS(7), 1,
sym_identifier, sym_identifier,
ACTIONS(194), 1, ACTIONS(194), 1,
@ -2498,19 +2498,19 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(240), 1, ACTIONS(240), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(242), 2, ACTIONS(242), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1529] = 2, [1529] = 2,
ACTIONS(244), 1, ACTIONS(244), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(246), 2, ACTIONS(246), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1537] = 2, [1537] = 2,
ACTIONS(248), 1, ACTIONS(248), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(250), 2, ACTIONS(250), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1545] = 1, [1545] = 1,
ACTIONS(252), 3, ACTIONS(252), 3,
@ -2521,12 +2521,12 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(254), 1, ACTIONS(254), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(256), 2, ACTIONS(256), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1559] = 1, [1559] = 1,
ACTIONS(250), 3, ACTIONS(250), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1565] = 3, [1565] = 3,
ACTIONS(258), 1, ACTIONS(258), 1,
@ -2544,7 +2544,7 @@ static const uint16_t ts_small_parse_table[] = {
ACTIONS(264), 1, ACTIONS(264), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(266), 2, ACTIONS(266), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1589] = 3, [1589] = 3,
ACTIONS(229), 1, ACTIONS(229), 1,
@ -2562,46 +2562,46 @@ static const uint16_t ts_small_parse_table[] = {
aux_sym__bracket_open_repeat1, aux_sym__bracket_open_repeat1,
[1609] = 1, [1609] = 1,
ACTIONS(274), 3, ACTIONS(274), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1615] = 1, [1615] = 1,
ACTIONS(276), 3, ACTIONS(276), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1621] = 2, [1621] = 2,
ACTIONS(278), 1, ACTIONS(278), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(274), 2, ACTIONS(274), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1629] = 2, [1629] = 2,
ACTIONS(280), 1, ACTIONS(280), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(276), 2, ACTIONS(276), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1637] = 2, [1637] = 2,
ACTIONS(282), 1, ACTIONS(282), 1,
ts_builtin_sym_end, ts_builtin_sym_end,
ACTIONS(284), 2, ACTIONS(284), 2,
sym_foreach, sym__foreach,
sym_identifier, sym_identifier,
[1645] = 1, [1645] = 1,
ACTIONS(284), 3, ACTIONS(284), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1651] = 1, [1651] = 1,
ACTIONS(266), 3, ACTIONS(266), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1657] = 1, [1657] = 1,
ACTIONS(286), 3, ACTIONS(286), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1663] = 3, [1663] = 3,
ACTIONS(288), 1, ACTIONS(288), 1,
@ -2629,18 +2629,18 @@ static const uint16_t ts_small_parse_table[] = {
anon_sym_RPAREN, anon_sym_RPAREN,
[1695] = 1, [1695] = 1,
ACTIONS(256), 3, ACTIONS(256), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1701] = 1, [1701] = 1,
ACTIONS(242), 3, ACTIONS(242), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1707] = 1, [1707] = 1,
ACTIONS(246), 3, ACTIONS(246), 3,
sym_foreach, sym__foreach,
sym_endforeach, sym__endforeach,
sym_identifier, sym_identifier,
[1713] = 2, [1713] = 2,
ACTIONS(298), 1, ACTIONS(298), 1,