Parse generator expression
This commit is contained in:
parent
7355866e1d
commit
d5a0b0b992
98
corpus/gen_exp.txt
Normal file
98
corpus/gen_exp.txt
Normal file
|
@ -0,0 +1,98 @@
|
|||
=======================================
|
||||
Unquoted generator expression [gen_exp]
|
||||
=======================================
|
||||
message($<>)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(gen_exp)))))
|
||||
|
||||
=====================================
|
||||
Quoted generator expression [gen_exp]
|
||||
=====================================
|
||||
message("$<>")
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(quoted_argument
|
||||
(quoted_element
|
||||
(gen_exp))))))
|
||||
|
||||
=====================
|
||||
No argument [gen_exp]
|
||||
=====================
|
||||
message($<ANGLE-R>)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(gen_exp
|
||||
(argument
|
||||
(unquoted_argument)))))))
|
||||
|
||||
============================================
|
||||
No argument with superfluous colon [gen_exp]
|
||||
============================================
|
||||
message($<ANGLE-R:>)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(gen_exp
|
||||
(argument
|
||||
(unquoted_argument)))))))
|
||||
|
||||
======================
|
||||
One argument [gen_exp]
|
||||
======================
|
||||
message($<BOOL:-NOTFOUND>)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(gen_exp
|
||||
(argument
|
||||
(unquoted_argument))
|
||||
(argument
|
||||
(unquoted_argument)))))))
|
||||
|
||||
=======================
|
||||
Two arguments [gen_exp]
|
||||
=======================
|
||||
message($<AND:TRUE,FALSE>)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(gen_exp
|
||||
(argument
|
||||
(unquoted_argument))
|
||||
(argument
|
||||
(unquoted_argument))
|
||||
(argument
|
||||
(unquoted_argument)))))))
|
|
@ -33,14 +33,18 @@ module.exports = grammar({
|
|||
env_var: ($) => seq("$", "ENV", "{", $.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),
|
||||
_untrimmed_argument: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $.argument, $._paren_argument),
|
||||
_paren_argument: ($) => seq("(", repeat($._untrimmed_argument), ")"),
|
||||
|
||||
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
|
||||
quoted_element: ($) => repeat1(choice($.variable_ref, /[^\\"]/, $.escape_sequence)),
|
||||
quoted_element: ($) => repeat1(choice($.variable_ref, $.gen_exp, /[^\\"]/, $.escape_sequence)),
|
||||
|
||||
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s()#\"\\]/, $.escape_sequence))),
|
||||
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, $.gen_exp, /[^\s()#\"\\]/, $.escape_sequence))),
|
||||
|
||||
if_command: ($) => command($.if, repeat($._untrimmed_argument)),
|
||||
elseif_command: ($) => command($.elseif, repeat($._untrimmed_argument)),
|
||||
|
|
|
@ -162,6 +162,89 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"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": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
@ -258,6 +341,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "variable_ref"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "gen_exp"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\\\\"]"
|
||||
|
@ -281,6 +368,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "variable_ref"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "gen_exp"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\s()#\\\"\\\\]"
|
||||
|
|
|
@ -370,6 +370,21 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "gen_exp",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "argument",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if_command",
|
||||
"named": true,
|
||||
|
@ -603,6 +618,10 @@
|
|||
"type": "escape_sequence",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "gen_exp",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable_ref",
|
||||
"named": true
|
||||
|
@ -665,6 +684,10 @@
|
|||
"type": "escape_sequence",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "gen_exp",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable_ref",
|
||||
"named": true
|
||||
|
@ -808,6 +831,18 @@
|
|||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "<",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ">",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CACHE",
|
||||
"named": false
|
||||
|
|
26794
src/parser.c
26794
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue