WIP: Merge 'select_case' and 'default_case'
Not sure whether I like this change or not... IMO this might be too lax.
This commit is contained in:
parent
4da69807ad
commit
ee37351e81
16
grammar.js
16
grammar.js
|
@ -2,10 +2,6 @@ function commaSeparated(elem) {
|
|||
return seq(elem, repeat(seq(",", elem)), optional(","))
|
||||
}
|
||||
|
||||
function trailingCommaSeparated(elem) {
|
||||
return repeat(seq(elem, ","))
|
||||
}
|
||||
|
||||
module.exports = grammar({
|
||||
name: "blueprint",
|
||||
|
||||
|
@ -153,24 +149,16 @@ module.exports = grammar({
|
|||
|
||||
_select_cases: ($) => seq(
|
||||
"{",
|
||||
optional(trailingCommaSeparated($.select_case)),
|
||||
// default *must* be the last one, enforced at parse-time...
|
||||
optional(seq(alias($.default_case, $.select_case), ",")),
|
||||
optional(repeat(seq($.select_case, ","))),
|
||||
"}",
|
||||
),
|
||||
|
||||
select_case: ($) => seq(
|
||||
field("pattern", $._string_literal),
|
||||
field("pattern", choice(alias("default", $.default), $._string_literal)),
|
||||
":",
|
||||
field("value", $._case_value)
|
||||
),
|
||||
|
||||
default_case: ($) => seq(
|
||||
field("pattern", alias("default", $.default)),
|
||||
":",
|
||||
field("value", $._case_value),
|
||||
),
|
||||
|
||||
_case_value: ($) => choice(
|
||||
alias("unset", $.unset),
|
||||
$._expr,
|
||||
|
|
74
src/grammar.json
generated
74
src/grammar.json
generated
|
@ -623,32 +623,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "default_case"
|
||||
},
|
||||
"named": true,
|
||||
"value": "select_case"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
|
@ -662,38 +636,22 @@
|
|||
"type": "FIELD",
|
||||
"name": "pattern",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_string_literal"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "value",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_case_value"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"default_case": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "pattern",
|
||||
"content": {
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "default"
|
||||
},
|
||||
"named": true,
|
||||
"value": "default"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "default"
|
||||
},
|
||||
"named": true,
|
||||
"value": "default"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_string_literal"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
1977
src/parser.c
generated
1977
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -130,10 +130,9 @@ foo = select(variant("VARIANT"), {
|
|||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(ERROR
|
||||
(select_case
|
||||
(default)
|
||||
(unset)))
|
||||
(select_case
|
||||
(default)
|
||||
(unset))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
|
|
Loading…
Reference in a new issue