Parse parenteses correctly

This commit is contained in:
Uy Ha 2021-07-01 13:36:35 +02:00
parent 44a026bbf5
commit 19bb3af0d5
4 changed files with 11663 additions and 11172 deletions

38
corpus/parentheses.txt Normal file
View file

@ -0,0 +1,38 @@
===================================================
Parentheses inside command invocation [parentheses]
===================================================
message(STATUS (TEST))
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
===========================================================
Missing parentheses inside command invocation [parentheses]
===========================================================
message(STATUS (TEST)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument)) (MISSING ")")
)
)
==================================================================
Nested missing parentheses inside command invocation [parentheses]
==================================================================
message(STATUS ((TEST))
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument)) (MISSING ")")
)
)

View file

@ -34,7 +34,8 @@ module.exports = grammar({
cache_var: ($) => seq("$", "CACHE", "{", $.variable, "}"), cache_var: ($) => seq("$", "CACHE", "{", $.variable, "}"),
argument: ($) => choice($.bracket_argument, $.quoted_argument, $.unquoted_argument), argument: ($) => choice($.bracket_argument, $.quoted_argument, $.unquoted_argument),
_untrimmed_argument: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $.argument), _untrimmed_argument: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $.argument, $._paren_argument),
_paren_argument: ($) => seq("(", $._untrimmed_argument, ")"),
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'), quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
quoted_element: ($) => repeat1(choice($.variable_ref, /[^\\"]/, $.escape_sequence)), quoted_element: ($) => repeat1(choice($.variable_ref, /[^\\"]/, $.escape_sequence)),

View file

@ -197,6 +197,27 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "argument" "name": "argument"
},
{
"type": "SYMBOL",
"name": "_paren_argument"
}
]
},
"_paren_argument": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_untrimmed_argument"
},
{
"type": "STRING",
"value": ")"
} }
] ]
}, },

22773
src/parser.c

File diff suppressed because it is too large Load diff