Add select binding

This commit is contained in:
Bruno BELANYI 2024-07-01 13:53:48 +00:00
parent 3e685cb691
commit 1fd9b67dbe
6 changed files with 1345 additions and 1156 deletions

View file

@ -164,9 +164,16 @@ module.exports = grammar({
$._string_literal,
$.boolean_literal,
alias("any", $.any),
$.pattern_binding,
alias("default", $.default),
),
pattern_binding: ($) => seq(
field("value", alias("any", $.any)),
field("operator", alias("@", $.operator)),
field("binding", $.identifier),
),
_case_value: ($) => choice(
alias("unset", $.unset),
$._expr,

43
src/grammar.json generated
View file

@ -744,6 +744,10 @@
"named": true,
"value": "any"
},
{
"type": "SYMBOL",
"name": "pattern_binding"
},
{
"type": "ALIAS",
"content": {
@ -755,6 +759,45 @@
}
]
},
"pattern_binding": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "any"
},
"named": true,
"value": "any"
}
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "@"
},
"named": true,
"value": "operator"
}
},
{
"type": "FIELD",
"name": "binding",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
"_case_value": {
"type": "CHOICE",
"members": [

40
src/node-types.json generated
View file

@ -321,6 +321,42 @@
}
}
},
{
"type": "pattern_binding",
"named": true,
"fields": {
"binding": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"operator": {
"multiple": false,
"required": true,
"types": [
{
"type": "operator",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "any",
"named": true
}
]
}
}
},
{
"type": "property",
"named": true,
@ -499,6 +535,10 @@
"type": "interpreted_string_literal",
"named": true
},
{
"type": "pattern_binding",
"named": true
},
{
"type": "raw_string_literal",
"named": true

2398
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -40,6 +40,7 @@ Select (soong config variable)
foo = select(soong_config_variable("my_namespace", "my_var"), {
"foo": unset,
"default": "bar",
any @ foo: unset,
})
--------------------------------------------------------------------------------
@ -62,7 +63,14 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
(interpreted_string_literal))
(select_case
(select_pattern
(pattern_binding
(any)
(operator)
(identifier)))
(unset))))))
================================================================================
Select (no default)

View file

@ -1,6 +1,9 @@
foo = select(soong_config_variable("my_namespace", "my_var"), {
// ^ keyword.conditional
"foo": unset,
any @ foo: unset,
// ^ operator
// ^ variable
default: "bar",
})