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, ","))
|
return repeat(seq(elem, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SELECTION_TYPES = [
|
||||||
|
// One argument
|
||||||
|
"product_variable",
|
||||||
|
"release_variable",
|
||||||
|
"variant",
|
||||||
|
// Two arguments
|
||||||
|
"soong_config_variable",
|
||||||
|
]
|
||||||
|
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
name: "bp",
|
name: "bp",
|
||||||
|
|
||||||
|
@ -121,37 +130,21 @@ module.exports = grammar({
|
||||||
select_expression: ($) => seq(
|
select_expression: ($) => seq(
|
||||||
"select",
|
"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(
|
select_value: ($) => seq(
|
||||||
field("type", alias(
|
field("type", alias(choice(...SELECTION_TYPES), $.selection_type)),
|
||||||
choice("product_variable", "release_variable", "variant"),
|
|
||||||
$.selection_type,
|
|
||||||
)),
|
|
||||||
"(",
|
"(",
|
||||||
field("condition", $._string_literal),
|
field("condition", commaSeparated($._string_literal)),
|
||||||
")",
|
")",
|
||||||
),
|
),
|
||||||
|
|
||||||
soong_config_variable: ($) => seq(
|
_select_cases: ($) => seq(
|
||||||
field("type", alias("soong_config_variable", $.selection_type)),
|
|
||||||
"(",
|
|
||||||
field(
|
|
||||||
"condition",
|
|
||||||
seq(
|
|
||||||
field("namespace", $._string_literal),
|
|
||||||
",",
|
|
||||||
field("variable", $._string_literal),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
")",
|
|
||||||
),
|
|
||||||
|
|
||||||
select_cases: ($) => seq(
|
|
||||||
"{",
|
"{",
|
||||||
optional(trailingCommaSeparated($.select_case)),
|
optional(trailingCommaSeparated($.select_case)),
|
||||||
// default *must* be the last one, enforced at parse-time...
|
// default *must* be the last one, enforced at parse-time...
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
(select_expression
|
(select_expression
|
||||||
")" @indent.branch)
|
")" @indent.branch)
|
||||||
|
|
||||||
(select_cases) @indent.begin
|
; FIXME: how to fix this
|
||||||
(select_cases
|
; (select_expression
|
||||||
"}" @indent.branch)
|
; "{" @indent.begin)
|
||||||
|
; (select_expression
|
||||||
|
; "}" @indent.branch)
|
||||||
; }}}
|
; }}}
|
||||||
|
|
||||||
; Declarations {{{
|
; 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": "("
|
"value": "("
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "CHOICE",
|
"type": "SYMBOL",
|
||||||
"members": [
|
"name": "select_value"
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "select_value"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "soong_config_variable"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -487,7 +478,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "select_cases"
|
"name": "_select_cases"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -517,6 +508,10 @@
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": "variant"
|
"value": "variant"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "soong_config_variable"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -528,40 +523,6 @@
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": "("
|
"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",
|
"type": "FIELD",
|
||||||
"name": "condition",
|
"name": "condition",
|
||||||
|
@ -569,24 +530,36 @@
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "SYMBOL",
|
||||||
"name": "namespace",
|
"name": "_string_literal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SEQ",
|
||||||
"name": "_string_literal"
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_string_literal"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "CHOICE",
|
||||||
"value": ","
|
"members": [
|
||||||
},
|
{
|
||||||
{
|
"type": "STRING",
|
||||||
"type": "FIELD",
|
"value": ","
|
||||||
"name": "variable",
|
},
|
||||||
"content": {
|
{
|
||||||
"type": "SYMBOL",
|
"type": "BLANK"
|
||||||
"name": "_string_literal"
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -597,7 +570,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"select_cases": {
|
"_select_cases": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"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",
|
"type": "select_expression",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -439,16 +424,12 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "select_cases",
|
"type": "select_case",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "select_value",
|
"type": "select_value",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "soong_config_variable",
|
|
||||||
"named": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -458,49 +439,13 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {
|
"fields": {
|
||||||
"condition": {
|
"condition": {
|
||||||
"multiple": false,
|
"multiple": true,
|
||||||
"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,
|
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": ",",
|
"type": ",",
|
||||||
"named": false
|
"named": false
|
||||||
}
|
},
|
||||||
]
|
|
||||||
},
|
|
||||||
"namespace": {
|
|
||||||
"multiple": false,
|
|
||||||
"required": true,
|
|
||||||
"types": [
|
|
||||||
{
|
{
|
||||||
"type": "interpreted_string_literal",
|
"type": "interpreted_string_literal",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -520,20 +465,6 @@
|
||||||
"named": true
|
"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
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(select_cases
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal))
|
||||||
(interpreted_string_literal))
|
(select_case
|
||||||
(select_case
|
(default)
|
||||||
(default)
|
(unset)))))
|
||||||
(unset))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (soong config variable)
|
Select (soong config variable)
|
||||||
|
@ -41,17 +40,16 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
|
||||||
(identifier)
|
(identifier)
|
||||||
(operator)
|
(operator)
|
||||||
(select_expression
|
(select_expression
|
||||||
(soong_config_variable
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(select_cases
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(unset))
|
||||||
(unset))
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal)))))
|
||||||
(interpreted_string_literal))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (no default)
|
Select (no default)
|
||||||
|
@ -74,19 +72,18 @@ foo = select(variant("arch"), {
|
||||||
(select_value
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(select_cases
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal))
|
||||||
(interpreted_string_literal))
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal))
|
||||||
(interpreted_string_literal))
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal))
|
||||||
(interpreted_string_literal))
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal)))))
|
||||||
(interpreted_string_literal))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (no values)
|
Select (no values)
|
||||||
|
@ -103,8 +100,7 @@ foo = select(variant("VARIANT"), {})
|
||||||
(select_expression
|
(select_expression
|
||||||
(select_value
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal)))))
|
||||||
(select_cases))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (default in wrong order)
|
Select (default in wrong order)
|
||||||
|
@ -128,23 +124,22 @@ foo = select(variant("VARIANT"), {
|
||||||
(select_value
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(select_cases
|
(select_case
|
||||||
|
(interpreted_string_literal)
|
||||||
|
(interpreted_string_literal))
|
||||||
|
(select_case
|
||||||
|
(interpreted_string_literal)
|
||||||
|
(interpreted_string_literal))
|
||||||
|
(ERROR
|
||||||
(select_case
|
(select_case
|
||||||
(interpreted_string_literal)
|
(default)
|
||||||
(interpreted_string_literal))
|
(unset)))
|
||||||
(select_case
|
(select_case
|
||||||
(interpreted_string_literal)
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(ERROR
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(default)
|
(interpreted_string_literal)))))
|
||||||
(unset)))
|
|
||||||
(select_case
|
|
||||||
(interpreted_string_literal)
|
|
||||||
(interpreted_string_literal))
|
|
||||||
(select_case
|
|
||||||
(interpreted_string_literal)
|
|
||||||
(interpreted_string_literal))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (no condition)
|
Select (no condition)
|
||||||
|
@ -165,13 +160,12 @@ foo = select(variant(), {
|
||||||
(select_value
|
(select_value
|
||||||
(selection_type)
|
(selection_type)
|
||||||
(MISSING raw_string_literal))
|
(MISSING raw_string_literal))
|
||||||
(select_cases
|
(select_case
|
||||||
(select_case
|
(interpreted_string_literal)
|
||||||
(interpreted_string_literal)
|
(unset))
|
||||||
(unset))
|
(select_case
|
||||||
(select_case
|
(default)
|
||||||
(default)
|
(interpreted_string_literal)))))
|
||||||
(interpreted_string_literal))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Select (invalid type)
|
Select (invalid type)
|
||||||
|
@ -197,6 +191,33 @@ foo = select(some_unknown_type("CONDITION"), {
|
||||||
(interpreted_string_literal))
|
(interpreted_string_literal))
|
||||||
(ERROR))
|
(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
|
Select as an identifier
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
Loading…
Reference in a new issue