Compare commits
5 commits
a2cc89a55c
...
e9632a29ba
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | e9632a29ba | ||
Bruno BELANYI | f283c14865 | ||
Bruno BELANYI | ff2a9b821d | ||
Bruno BELANYI | b04cd92189 | ||
Bruno BELANYI | 6d6d9fc03b |
37
grammar.js
37
grammar.js
|
@ -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...
|
||||
|
|
|
@ -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
14
queries/locals.scm
Normal 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
95
src/grammar.json
generated
|
@ -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
75
src/node-types.json
generated
|
@ -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
1772
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
================================================================================
|
||||
|
|
Loading…
Reference in a new issue