Make $.variable recursive

This commit is contained in:
Uy Ha 2021-06-30 07:40:33 +02:00
parent b8c45d2a2b
commit 12ef0b4cab
6 changed files with 8745 additions and 8322 deletions

View file

@ -96,3 +96,23 @@ message("${var} ${var}")
)
)
)
======================================================================
Variable reference inside another variable reference [quoted_argument]
======================================================================
message("${var_${var}}")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)
)

View file

@ -85,3 +85,20 @@ message(${var_ref})
)
)
====================================================================
Variable referencing inside variable referencing [unquoted_argument]
====================================================================
message(${var_${var_ref}})
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)

View file

@ -27,7 +27,7 @@ module.exports = grammar({
_escape_encoded: (_) => choice("\\t", "\\r", "\\n"),
_escape_semicolon: (_) => ";",
variable: ($) => prec.left(repeat1(choice(/[a-zA-Z0-9/_.+-]/, $.escape_sequence))),
variable: ($) => prec.left(repeat1(choice(/[a-zA-Z0-9/_.+-]/, $.escape_sequence, $.variable_ref))),
variable_ref: ($) => choice($.normal_var, $.env_var, $.cache_var),
normal_var: ($) => seq("${", $.variable, "}"),
env_var: ($) => seq("$ENV", "{", $.variable, "}"),

View file

@ -65,6 +65,10 @@
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SYMBOL",
"name": "variable_ref"
}
]
}

View file

@ -579,6 +579,10 @@
{
"type": "escape_sequence",
"named": true
},
{
"type": "variable_ref",
"named": true
}
]
}

17018
src/parser.c

File diff suppressed because it is too large Load diff