Add multi-valued select expression

This commit is contained in:
Bruno BELANYI 2024-04-23 15:43:10 +00:00
parent 0816633d9a
commit d01bcf0f6d
5 changed files with 1926 additions and 1178 deletions

View file

@ -131,7 +131,12 @@ module.exports = grammar({
")",
),
select_value: ($) => seq(
select_value: ($) => choice(
$._select_value,
seq("(", commaSeparatedOptTrailing($._select_value), ")"),
),
_select_value: ($) => seq(
field("name", $.identifier),
"(",
field("arguments", optional(commaSeparatedNoTrailing($._string_literal))),
@ -145,13 +150,20 @@ module.exports = grammar({
),
select_case: ($) => seq(
field("pattern", choice(
field("pattern", $.select_pattern),
":",
field("value", $._case_value)
),
select_pattern: ($) => choice(
$._select_pattern,
seq("(", commaSeparatedOptTrailing($._select_pattern), ")"),
),
_select_pattern: ($) => choice(
$._string_literal,
$.boolean_literal,
alias("default", $.default),
)),
":",
field("value", $._case_value)
),
_case_value: ($) => choice(

152
src/grammar.json generated
View file

@ -487,6 +487,65 @@
]
},
"select_value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_select_value"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_select_value"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_select_value"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_select_value": {
"type": "SEQ",
"members": [
{
@ -588,6 +647,84 @@
"type": "FIELD",
"name": "pattern",
"content": {
"type": "SYMBOL",
"name": "select_pattern"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_case_value"
}
}
]
},
"select_pattern": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_select_pattern"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_select_pattern"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_select_pattern"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_select_pattern": {
"type": "CHOICE",
"members": [
{
@ -608,21 +745,6 @@
"value": "default"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_case_value"
}
}
]
},
"_case_value": {
"type": "CHOICE",

43
src/node-types.json generated
View file

@ -354,19 +354,7 @@
"required": true,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"type": "select_pattern",
"named": true
}
]
@ -453,6 +441,33 @@
]
}
},
{
"type": "select_pattern",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
}
},
{
"type": "select_value",
"named": true,
@ -476,7 +491,7 @@
]
},
"name": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{

2753
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -19,10 +19,12 @@ foo = select(release_variable("RELEASE_TEST"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(unset))))))
================================================================================
@ -47,10 +49,12 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(unset))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -76,16 +80,20 @@ foo = select(variant("arch"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -130,19 +138,24 @@ foo = select(variant("VARIANT"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(unset))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -165,10 +178,12 @@ foo = select(variant(), {
(identifier))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(unset))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
@ -192,10 +207,12 @@ foo = select(some_unknown_type("CONDITION"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
@ -220,10 +237,12 @@ foo = select(release_variable("ONE", "TWO"), {
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
@ -248,10 +267,65 @@ foo = select(some_boolean("VALUE",), {
(ERROR))
(select_cases
(select_case
(boolean_literal)
(select_pattern
(boolean_literal))
(interpreted_string_literal))
(select_case
(boolean_literal)
(select_pattern
(boolean_literal))
(interpreted_string_literal))))))
================================================================================
Select (trailing comma in values)
================================================================================
foo = select((
arch(),
os(),
), {
(default, default): "true",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(identifier)
(identifier))
(select_cases
(select_case
(select_pattern
(default)
(default))
(interpreted_string_literal))))))
================================================================================
Select (trailing comma in pattern)
================================================================================
foo = select((arch(), os()), {
(default, default,): "true",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(identifier)
(identifier))
(select_cases
(select_case
(select_pattern
(default)
(default))
(interpreted_string_literal))))))
================================================================================
@ -275,10 +349,12 @@ foo = select(some_boolean("IS_TRUE"), {
(interpreted_string_literal))
(select_cases
(select_case
(boolean_literal)
(select_pattern
(boolean_literal))
(interpreted_string_literal))
(select_case
(boolean_literal)
(select_pattern
(boolean_literal))
(interpreted_string_literal))))))
================================================================================