Relax ordering in 'select' cases

We shouldn't really care whether or not `default` *is* the last value...
This commit is contained in:
Bruno BELANYI 2024-04-23 14:38:32 +00:00
parent 93a71d095b
commit b2e113a821
4 changed files with 1035 additions and 1241 deletions

View file

@ -154,23 +154,18 @@ 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), ",")),
"}",
),
select_case: ($) => seq(
field("pattern", $._string_literal),
field("pattern", choice(
$._string_literal,
alias("default", $.default),
)),
":",
field("value", $._case_value)
),
default_case: ($) => seq(
field("pattern", alias("default", $.default)),
":",
field("value", $._case_value),
),
_case_value: ($) => choice(
alias("unset", $.unset),
$._expr,

56
src/grammar.json generated
View file

@ -628,32 +628,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": "}"
@ -667,31 +641,13 @@
"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",
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "pattern",
"content": {
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
@ -700,6 +656,8 @@
"named": true,
"value": "default"
}
]
}
},
{
"type": "STRING",

2182
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -135,10 +135,9 @@ foo = select(variant("VARIANT"), {
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(ERROR
(select_case
(default)
(unset)))
(unset))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))