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
(foreach_loop
(foreach_command
(foreach)
(arguments (argument (unquoted_argument)))
)
(endforeach_command
(endforeach)
)
(endforeach_command)
)
)
@ -31,11 +28,9 @@ endforeach(var)
(source_file
(foreach_loop
(foreach_command
(foreach)
(arguments (argument (unquoted_argument)))
)
(endforeach_command
(endforeach)
(argument (unquoted_argument))
)
))
@ -52,12 +47,9 @@ ENDFOREACH()
(source_file
(foreach_loop
(foreach_command
(foreach)
(arguments (argument (unquoted_argument)))
)
(endforeach_command
(endforeach)
)
(endforeach_command)
)
)
@ -73,11 +65,8 @@ endForEach()
(source_file
(foreach_loop
(foreach_command
(foreach)
(arguments (argument (unquoted_argument)))
)
(endforeach_command
(endforeach)
)
(endforeach_command)
)
)

View file

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

View file

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

View file

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

View file

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