Compare commits

...

8 commits

Author SHA1 Message Date
Bruno BELANYI 295e3956a3 WIP
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-10 15:24:03 +00:00
Bruno BELANYI ee37351e81 WIP: Merge 'select_case' and 'default_case'
Not sure whether I like this change or not... IMO this might be too lax.
2024-04-10 15:24:03 +00:00
Bruno BELANYI 4da69807ad Alias 'default_case' to 'select_case'
There's not much use in the node being a different name.
2024-04-10 15:24:03 +00:00
Bruno BELANYI 9049b4f4b9 Add 'default' alias
This makes it appear in the tree as a named node.
2024-04-10 15:24:02 +00:00
Bruno BELANYI e0aa749e1b Hide 'select_cases' rule
It doesn't provide any more information to expose it.
2024-04-10 15:24:01 +00:00
Bruno BELANYI f6e1266493 Consider module as function call for highlighting
All checks were successful
ci/woodpecker/push/check Pipeline was successful
Their semantic is closer to a function call (like i.e: Bazel rules)
rather than a module/namespace.

Similarly for their properties, which are more like parameters than
members.
2024-04-10 15:21:07 +00:00
Bruno BELANYI be1e3f07d3 Make 'line_comment' more explicit about newlines
Because of the way regular expressions work, they were already bounded
at newlines here, but explicit is better than implicit :-).
2024-04-10 15:20:29 +00:00
Bruno BELANYI 73b0797891 Add builtins highlighting 2024-04-10 15:20:29 +00:00
11 changed files with 1034 additions and 1290 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",
@ -23,7 +19,7 @@ module.exports = grammar({
$.module,
),
line_comment: (_) => seq("//", /.*/),
line_comment: (_) => seq("//", /[^\n]*/),
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
@ -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

@ -42,11 +42,19 @@
(identifier) @variable
(module
type: (identifier) @module)
type: (identifier) @function.call)
(module
(property
field: (identifier) @variable.member))
field: (identifier) @variable.parameter))
; }}}
; Built-ins {{{
[
(unset)
(default)
] @variable.builtin
(selection_type) @function.builtin
; }}}
; Expressions {{{

70
src/grammar.json generated
View file

@ -30,7 +30,7 @@
},
{
"type": "PATTERN",
"value": ".*"
"value": "[^\\n]*"
}
]
},
@ -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

@ -85,6 +85,23 @@ Block comment with asterisks
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment (multiline)
================================================================================
/*
This
is
a
long
comment
*/
--------------------------------------------------------------------------------
(source_file
(block_comment))

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,7 +185,8 @@ foo = select(some_unknown_type("CONDITION"), {
(identifier)
(identifier)
(interpreted_string_literal)
(interpreted_string_literal))
(interpreted_string_literal)
(default))
(interpreted_string_literal))
(ERROR))

View file

@ -0,0 +1,8 @@
foo = select(soong_config_variable("my_namespace", "my_var"), {
// ^ function.builtin
"foo": unset,
// ^ variable.builtin
default: select(variant("VARIANT"), {}),
// <- variable.builtin
// ^ function.builtin
})

View file

@ -1,21 +1,21 @@
foo {}
// <- module
// <- function.call
foo ()
// <- module
// <- function.call
foo {
// <- module
// <- function.call
field: 12,
// <- variable.member
// <- variable.parameter
another_field: 27,
// <- variable.member
// <- variable.parameter
}
foo (
// <- module
// <- function.call
field = 42,
// <- variable.member
// <- variable.parameter
done = false,
// <- variable.member
// <- variable.parameter
)

View file

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

View file

@ -11,5 +11,5 @@ select = 42
// Or module property
foo {
select: 42,
// <- variable.member
// <- variable.parameter
}