feat!: remove parsing generator expressions

Parsing generator expressions statically is impossible since whether an argument is
interpreted as a generator expression or not depends on the function itself. Hence, the
parsing for it is removed.
This commit is contained in:
Uy Ha 2024-06-05 08:32:29 +00:00
parent a4bc80390f
commit a414a4c83d
5 changed files with 13783 additions and 15601 deletions

View file

@ -35,20 +35,15 @@ module.exports = grammar({
env_var: ($) => seq("$", "ENV", "{", $.variable, "}"), env_var: ($) => seq("$", "ENV", "{", $.variable, "}"),
cache_var: ($) => seq("$", "CACHE", "{", $.variable, "}"), cache_var: ($) => seq("$", "CACHE", "{", $.variable, "}"),
gen_exp: ($) => seq("$", "<", optional($._gen_exp_content), ">"),
_gen_exp_content: ($) => seq($.argument, optional($._gen_exp_arguments)),
_gen_exp_arguments: ($) => seq(":", repeat(seq($.argument, optional(/[,;]/)))),
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, $._paren_argument), _untrimmed_argument: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $.argument, $._paren_argument),
_paren_argument: ($) => seq("(", repeat($._untrimmed_argument), ")"), _paren_argument: ($) => seq("(", repeat($._untrimmed_argument), ")"),
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'), quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
quoted_element: ($) => repeat1(choice($.variable_ref, $.gen_exp, $._quoted_text, $.escape_sequence)), quoted_element: ($) => repeat1(choice($.variable_ref, $._quoted_text, $.escape_sequence)),
_quoted_text: (_) => prec.left(repeat1(choice("$", /[^\\"]/))), _quoted_text: (_) => prec.left(repeat1(choice("$", /[^\\"]/))),
unquoted_argument: ($) => unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, $._unquoted_text, $.escape_sequence))),
prec.right(repeat1(choice($.variable_ref, $.gen_exp, $._unquoted_text, $.escape_sequence))),
_unquoted_text: (_) => prec.left(repeat1(choice("$", /[^()#"\\]/))), _unquoted_text: (_) => prec.left(repeat1(choice("$", /[^()#"\\]/))),
body: ($) => prec.right(repeat1($._untrimmed_command_invocation)), body: ($) => prec.right(repeat1($._untrimmed_command_invocation)),

91
src/grammar.json generated
View file

@ -171,89 +171,6 @@
} }
] ]
}, },
"gen_exp": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_gen_exp_content"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ">"
}
]
},
"_gen_exp_content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_gen_exp_arguments"
},
{
"type": "BLANK"
}
]
}
]
},
"_gen_exp_arguments": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[,;]"
},
{
"type": "BLANK"
}
]
}
]
}
}
]
},
"argument": { "argument": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -350,10 +267,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "variable_ref" "name": "variable_ref"
}, },
{
"type": "SYMBOL",
"name": "gen_exp"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_quoted_text" "name": "_quoted_text"
@ -397,10 +310,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "variable_ref" "name": "variable_ref"
}, },
{
"type": "SYMBOL",
"name": "gen_exp"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_unquoted_text" "name": "_unquoted_text"

35
src/node-types.json generated
View file

@ -405,21 +405,6 @@
] ]
} }
}, },
{
"type": "gen_exp",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "argument",
"named": true
}
]
}
},
{ {
"type": "if_command", "type": "if_command",
"named": true, "named": true,
@ -573,10 +558,6 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "gen_exp",
"named": true
},
{ {
"type": "variable_ref", "type": "variable_ref",
"named": true "named": true
@ -643,10 +624,6 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "gen_exp",
"named": true
},
{ {
"type": "variable_ref", "type": "variable_ref",
"named": true "named": true
@ -754,22 +731,10 @@
"type": ")", "type": ")",
"named": false "named": false
}, },
{
"type": ":",
"named": false
},
{ {
"type": ";", "type": ";",
"named": false "named": false
}, },
{
"type": "<",
"named": false
},
{
"type": ">",
"named": false
},
{ {
"type": "CACHE", "type": "CACHE",
"named": false "named": false

29183
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
======
OpenCV
======
if(dep MATCHES "^\\$<LINK_ONLY:([^>]+)>$")
set(dep "${CMAKE_MATCH_1}")
endif()
if(dep MATCHES "^\\$<")
message(WARNING "Unexpected CMake generator expression: ${dep}")
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument
(unquoted_argument))
(argument
(unquoted_argument))
(argument
(quoted_argument
(quoted_element
(escape_sequence))))))
(body
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument))
(argument
(quoted_argument
(quoted_element
(variable_ref
(normal_var
(variable)))))))))
(endif_command
(endif)))
(if_condition
(if_command
(if)
(argument_list
(argument
(unquoted_argument))
(argument
(unquoted_argument))
(argument
(quoted_argument
(quoted_element
(escape_sequence))))))
(body
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument))
(argument
(quoted_argument
(quoted_element
(variable_ref
(normal_var
(variable)))))))))
(endif_command
(endif))))