Fix bug regarding dollar sign but not variable reference

This commit is contained in:
Uy Ha 2022-01-26 19:41:41 +01:00
parent 87795ad552
commit 5020572408
6 changed files with 15453 additions and 13957 deletions

View file

@ -156,3 +156,21 @@ message("${var_${var}} #comment")
)
)
)
===========================================================
Lookalike variable inside quoted argument [quoted_argument]
===========================================================
message("$var")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element)
)
)
)
)

View file

@ -102,3 +102,18 @@ message(${var_${var_ref}})
)
)
===============================================================
Lookalike variable inside unquoted argument [unquoted_argument]
===============================================================
message($var)
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument)
)
)
)

View file

@ -42,9 +42,11 @@ module.exports = grammar({
_paren_argument: ($) => seq("(", repeat($._untrimmed_argument), ")"),
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
quoted_element: ($) => repeat1(choice($.variable_ref, $.gen_exp, /[^\\"]/, $.escape_sequence)),
quoted_element: ($) => repeat1(choice($.variable_ref, $.gen_exp, $._quoted_text, $.escape_sequence)),
_quoted_text: ($) => prec.left(repeat1(choice('$', /[^\\"]/))),
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, $.gen_exp, /[^\s()#\"\\]/, $.escape_sequence))),
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, $.gen_exp, $._unquoted_text, $.escape_sequence))),
_unquoted_text: ($) => prec.left(repeat1(choice('$', /[^()#"\\']/))),
if_command: ($) => command($.if, repeat($._untrimmed_argument)),
elseif_command: ($) => command($.elseif, repeat($._untrimmed_argument)),

View file

@ -346,8 +346,8 @@
"name": "gen_exp"
},
{
"type": "PATTERN",
"value": "[^\\\\\"]"
"type": "SYMBOL",
"name": "_quoted_text"
},
{
"type": "SYMBOL",
@ -356,6 +356,26 @@
]
}
},
"_quoted_text": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "PATTERN",
"value": "[^\\\\\"]"
}
]
}
}
},
"unquoted_argument": {
"type": "PREC_RIGHT",
"value": 0,
@ -373,8 +393,8 @@
"name": "gen_exp"
},
{
"type": "PATTERN",
"value": "[^\\s()#\\\"\\\\]"
"type": "SYMBOL",
"name": "_unquoted_text"
},
{
"type": "SYMBOL",
@ -384,6 +404,26 @@
}
}
},
"_unquoted_text": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "PATTERN",
"value": "[^()#\"\\\\']"
}
]
}
}
},
"if_command": {
"type": "SEQ",
"members": [

29322
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -123,6 +123,7 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*