Compare commits

...

5 commits

Author SHA1 Message Date
Bruno BELANYI e9632a29ba Merge soong_config_variable into select_value
Some checks failed
ci/woodpecker/push/check Pipeline failed
It makes the parse tree easier to use, and I don't think we need to care
for the lax parsing.
2024-04-14 13:11:37 +01:00
Bruno BELANYI f283c14865 WIP 2024-04-14 13:00:17 +01:00
Bruno BELANYI ff2a9b821d WIP(tests): Hide 'select_cases' rule
Some checks failed
ci/woodpecker/push/check Pipeline failed
It doesn't provide any more information to expose it.
2024-04-14 13:00:17 +01:00
Bruno BELANYI b04cd92189 Add locals queries
All checks were successful
ci/woodpecker/push/check Pipeline was successful
Once again, treating module as function calls, since that's basically
what they are...
2024-04-14 13:00:17 +01:00
Bruno BELANYI 6d6d9fc03b Add test for multiple arguments in selection type 2024-04-14 13:00:17 +01:00
7 changed files with 1055 additions and 1073 deletions

View file

@ -6,6 +6,15 @@ function trailingCommaSeparated(elem) {
return repeat(seq(elem, ","))
}
const SELECTION_TYPES = [
// One argument
"product_variable",
"release_variable",
"variant",
// Two arguments
"soong_config_variable",
]
module.exports = grammar({
name: "bp",
@ -121,37 +130,21 @@ module.exports = grammar({
select_expression: ($) => seq(
"select",
"(",
choice($.select_value, $.soong_config_variable),
$.select_value,
",",
$.select_cases,
$._select_cases,
")",
),
// Allow for some incorrect usage, to make the parse tree simpler
select_value: ($) => seq(
field("type", alias(
choice("product_variable", "release_variable", "variant"),
$.selection_type,
)),
field("type", alias(choice(...SELECTION_TYPES), $.selection_type)),
"(",
field("condition", $._string_literal),
field("condition", commaSeparated($._string_literal)),
")",
),
soong_config_variable: ($) => seq(
field("type", alias("soong_config_variable", $.selection_type)),
"(",
field(
"condition",
seq(
field("namespace", $._string_literal),
",",
field("variable", $._string_literal),
),
),
")",
),
select_cases: ($) => seq(
_select_cases: ($) => seq(
"{",
optional(trailingCommaSeparated($.select_case)),
// default *must* be the last one, enforced at parse-time...

View file

@ -11,9 +11,11 @@
(select_expression
")" @indent.branch)
(select_cases) @indent.begin
(select_cases
"}" @indent.branch)
; FIXME: how to fix this
; (select_expression
; "{" @indent.begin)
; (select_expression
; "}" @indent.branch)
; }}}
; Declarations {{{

14
queries/locals.scm Normal file
View file

@ -0,0 +1,14 @@
(module
(property
field: (identifier) @local.definition.parameter))
(map_expression
(property
field: (identifier) @local.definition.field))
(assignment
left: (identifier) @local.definition.var)
(identifier) @local.reference
; vim: sw=2 foldmethod=marker

95
src/grammar.json generated
View file

@ -469,17 +469,8 @@
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "select_value"
},
{
"type": "SYMBOL",
"name": "soong_config_variable"
}
]
"type": "SYMBOL",
"name": "select_value"
},
{
"type": "STRING",
@ -487,7 +478,7 @@
},
{
"type": "SYMBOL",
"name": "select_cases"
"name": "_select_cases"
},
{
"type": "STRING",
@ -517,6 +508,10 @@
{
"type": "STRING",
"value": "variant"
},
{
"type": "STRING",
"value": "soong_config_variable"
}
]
},
@ -528,40 +523,6 @@
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "condition",
"content": {
"type": "SYMBOL",
"name": "_string_literal"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"soong_config_variable": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "soong_config_variable"
},
"named": true,
"value": "selection_type"
}
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "condition",
@ -569,24 +530,36 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "namespace",
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_string_literal"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_string_literal"
}
]
}
},
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "_string_literal"
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
@ -597,7 +570,7 @@
}
]
},
"select_cases": {
"_select_cases": {
"type": "SEQ",
"members": [
{

75
src/node-types.json generated
View file

@ -415,21 +415,6 @@
}
}
},
{
"type": "select_cases",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "select_case",
"named": true
}
]
}
},
{
"type": "select_expression",
"named": true,
@ -439,16 +424,12 @@
"required": true,
"types": [
{
"type": "select_cases",
"type": "select_case",
"named": true
},
{
"type": "select_value",
"named": true
},
{
"type": "soong_config_variable",
"named": true
}
]
}
@ -458,49 +439,13 @@
"named": true,
"fields": {
"condition": {
"multiple": false,
"required": true,
"types": [
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "selection_type",
"named": true
}
]
}
}
},
{
"type": "soong_config_variable",
"named": true,
"fields": {
"condition": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": ",",
"named": false
}
]
},
"namespace": {
"multiple": false,
"required": true,
"types": [
},
{
"type": "interpreted_string_literal",
"named": true
@ -520,20 +465,6 @@
"named": true
}
]
},
"variable": {
"multiple": false,
"required": true,
"types": [
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
}
}
},

1772
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -17,13 +17,12 @@ foo = select(release_variable("RELEASE_TEST"), {
(select_value
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(default)
(unset))))))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(default)
(unset)))))
================================================================================
Select (soong config variable)
@ -41,17 +40,16 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(identifier)
(operator)
(select_expression
(soong_config_variable
(select_value
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(unset))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))))))
(select_case
(interpreted_string_literal)
(unset))
(select_case
(interpreted_string_literal)
(interpreted_string_literal)))))
================================================================================
Select (no default)
@ -74,19 +72,18 @@ foo = select(variant("arch"), {
(select_value
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))))))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal)))))
================================================================================
Select (no values)
@ -103,8 +100,7 @@ foo = select(variant("VARIANT"), {})
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(select_cases))))
(interpreted_string_literal)))))
================================================================================
Select (default in wrong order)
@ -128,23 +124,22 @@ foo = select(variant("VARIANT"), {
(select_value
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(ERROR
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(ERROR
(select_case
(default)
(unset)))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))))))
(default)
(unset)))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal)))))
================================================================================
Select (no condition)
@ -165,13 +160,12 @@ foo = select(variant(), {
(select_value
(selection_type)
(MISSING raw_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(unset))
(select_case
(default)
(interpreted_string_literal))))))
(select_case
(interpreted_string_literal)
(unset))
(select_case
(default)
(interpreted_string_literal)))))
================================================================================
Select (invalid type)
@ -197,6 +191,33 @@ foo = select(some_unknown_type("CONDITION"), {
(interpreted_string_literal))
(ERROR))
================================================================================
Select (multiple type arguments)
================================================================================
foo = select(release_variable("ONE", "TWO"), {
"d": "d2",
default: "f2",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(default)
(interpreted_string_literal)))))
================================================================================
Select as an identifier
================================================================================