Compare commits

...

10 commits

Author SHA1 Message Date
Bruno BELANYI e4653b2535 WIP
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-09 13:12:10 +01:00
Bruno BELANYI 4727086526 WIP: Merge 'select_case' and 'default_case'
Not sure whether I like this change or not... IMO this might be too lax.
2024-04-09 13:11:53 +01:00
Bruno BELANYI 41d50aca38 Alias 'default_case' to 'select_case'
There's not much use in the node being a different name.
2024-04-09 13:09:48 +01:00
Bruno BELANYI 5082de5c7f Add 'default' alias
This makes it appear in the tree as a named node.
2024-04-09 13:08:02 +01:00
Bruno BELANYI e711defc41 Hide 'select_cases' rule
It doesn't provide any more information to expose it.
2024-04-09 12:49:36 +01:00
Bruno BELANYI ba2022d3c8 Add builtins highlighting
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-09 12:28:28 +01:00
Bruno BELANYI 3475d713d5 Add 'select' highlighting 2024-04-09 12:28:28 +01:00
Bruno BELANYI ddb4f693be Add test for 'select' as an identifier 2024-04-09 12:28:28 +01:00
Bruno BELANYI ab6d235540 Add map properties highlighting 2024-04-09 12:28:28 +01:00
Bruno BELANYI 42bef1d592 Add punctuations highlighting 2024-04-09 12:28:28 +01:00
10 changed files with 1094 additions and 1276 deletions

View file

@ -2,10 +2,6 @@ function commaSeparated(elem) {
return seq(elem, repeat(seq(",", elem)), optional(","))
}
function trailingCommaSeparated(elem) {
return repeat(seq(elem, ","))
}
module.exports = grammar({
name: "blueprint",
@ -123,10 +119,11 @@ module.exports = grammar({
"(",
choice($.select_value, $.soong_config_variable),
",",
$.select_cases,
$._select_cases,
")",
),
// FIXME: simplify with 'soong_config_variable'?
select_value: ($) => seq(
field("type", alias(
choice("product_variable", "release_variable", "variant"),
@ -137,6 +134,7 @@ module.exports = grammar({
")",
),
// FIXME
soong_config_variable: ($) => seq(
field("type", alias("soong_config_variable", $.selection_type)),
"(",
@ -151,26 +149,18 @@ module.exports = grammar({
")",
),
select_cases: ($) => seq(
_select_cases: ($) => seq(
"{",
optional(trailingCommaSeparated($.select_case)),
// default *must* be the last one, enforced at parse-time...
optional(seq($.default_case, ",")),
optional(repeat(seq($.select_case, ","))),
"}",
),
select_case: ($) => seq(
field("pattern", $._string_literal),
field("pattern", choice(alias("default", $.default), $._string_literal)),
":",
field("value", $._case_value)
),
default_case: ($) => seq(
field("pattern", "default"),
":",
field("value", $._case_value),
),
_case_value: ($) => choice(
alias("unset", $.unset),
$._expr,

View file

@ -9,6 +9,22 @@
(integer_literal ("-") @operator)
; }}}
; Punctuation {{{
[
","
":"
] @punctuation.delimiter
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
; }}}
; Literal {{{
(boolean_literal) @boolean
@ -33,4 +49,21 @@
field: (identifier) @variable.member))
; }}}
; Built-ins {{{
[
(unset)
(default)
] @variable.builtin
(selection_type) @function.builtin
; }}}
; Expressions {{{
(map_expression
(property
field: (identifier) @property))
(select_expression
"select" @keyword.conditional)
; }}}
; vim: sw=2 foldmethod=marker

68
src/grammar.json generated
View file

@ -482,7 +482,7 @@
},
{
"type": "SYMBOL",
"name": "select_cases"
"name": "_select_cases"
},
{
"type": "STRING",
@ -592,7 +592,7 @@
}
]
},
"select_cases": {
"_select_cases": {
"type": "SEQ",
"members": [
{
@ -623,27 +623,6 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "default_case"
},
{
"type": "STRING",
"value": ","
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
@ -657,33 +636,22 @@
"type": "FIELD",
"name": "pattern",
"content": {
"type": "SYMBOL",
"name": "_string_literal"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_case_value"
}
}
]
},
"default_case": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "pattern",
"content": {
"type": "STRING",
"value": "default"
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
},
{
"type": "SYMBOL",
"name": "_string_literal"
}
]
}
},
{

89
src/node-types.json generated
View file

@ -177,68 +177,6 @@
"named": true,
"fields": {}
},
{
"type": "default_case",
"named": true,
"fields": {
"pattern": {
"multiple": false,
"required": true,
"types": [
{
"type": "default",
"named": false
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
},
{
"type": "unset",
"named": true
}
]
}
}
},
{
"type": "integer_literal",
"named": true,
@ -420,6 +358,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
@ -478,25 +420,6 @@
}
}
},
{
"type": "select_cases",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "default_case",
"named": true
},
{
"type": "select_case",
"named": true
}
]
}
},
{
"type": "select_expression",
"named": true,
@ -506,7 +429,7 @@
"required": true,
"types": [
{
"type": "select_cases",
"type": "select_case",
"named": true
},
{
@ -673,7 +596,7 @@
},
{
"type": "default",
"named": false
"named": true
},
{
"type": "escape_sequence",

1985
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -17,12 +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))
(default_case
(unset))))))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(default)
(unset)))))
================================================================================
Select (soong config variable)
@ -44,13 +44,12 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(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)
@ -73,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)
@ -102,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)
@ -127,22 +124,21 @@ 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
(default_case
(unset)))
(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
(default)
(unset))
(select_case
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(interpreted_string_literal)))))
================================================================================
Select (no condition)
@ -163,12 +159,12 @@ foo = select(variant(), {
(select_value
(selection_type)
(MISSING raw_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(unset))
(default_case
(interpreted_string_literal))))))
(select_case
(interpreted_string_literal)
(unset))
(select_case
(default)
(interpreted_string_literal)))))
================================================================================
Select (invalid type)
@ -189,6 +185,30 @@ foo = select(some_unknown_type("CONDITION"), {
(identifier)
(identifier)
(interpreted_string_literal)
(interpreted_string_literal))
(interpreted_string_literal)
(default))
(interpreted_string_literal))
(ERROR))
================================================================================
Select as an identifier
================================================================================
select = 42
foo {
select: false,
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(module
(identifier)
(property
(identifier)
(boolean_literal))))

View file

@ -0,0 +1,14 @@
foo = select(soong_config_variable("my_namespace", "my_var"), {
// ^ function.builtin
"foo": unset,
// ^ variable.builtin
default: select(variant("VARIANT") {}),
// <- variable.builtin
// ^ function.builtin
})
/* Assigning to builtins is conveniently not allowed at runtime */
unset = 12
// <- variable.builtin
default = 27
// <- variable.builtin

View file

@ -0,0 +1,7 @@
foo {
field: {
// <- variable.member
key: 42,
// <- property
},
}

View file

@ -0,0 +1,15 @@
foo (
// <- punctuation.bracket
bar = [
//^ punctuation.bracket
{
// <- punctuation.bracket
key: "value",
// ^ punctuation.delimiter
// ^ punctuation.delimiter
},
// <- punctuation.bracket
]
// <- punctuation.bracket
)
// <- punctuation.bracket

15
test/highlight/select.bp Normal file
View file

@ -0,0 +1,15 @@
foo = select(soong_config_variable("my_namespace", "my_var"), {
// ^ keyword.conditional
"foo": unset,
default: "bar",
})
// It can still be used as a normal variable name
select = 42
// <- variable
// Or module property
foo {
select: 42,
// <- variable.member
}