Compare commits

...

10 commits

Author SHA1 Message Date
Bruno BELANYI aa06bb8b9f WIP: Add indentation queries for multi-value 'select'
Some checks failed
ci/woodpecker/push/check Pipeline failed
2024-04-23 16:36:11 +00:00
Bruno BELANYI 626ffea712 Add queries to Rust bindings
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-23 15:52:56 +00:00
Bruno BELANYI 6918efba46 Add queries to 'package.json' 2024-04-23 15:52:56 +00:00
Bruno BELANYI d5654de519 Expose 'condition' node 2024-04-23 15:47:30 +00:00
Bruno BELANYI f267a5be95 Add multi-valued select expression 2024-04-23 15:43:10 +00:00
Bruno BELANYI 96ae542119 Name 'commaSeparated*' helpers consistently 2024-04-23 15:27:52 +00:00
Bruno BELANYI 8166742493 Remove trailing commas in 'select_value' arguments 2024-04-23 15:23:06 +00:00
Bruno BELANYI 7d8f958a90 Add boolean-typed select values 2024-04-23 15:14:16 +00:00
Bruno BELANYI 3bc77aab19 Remove 'selection_type' alias 2024-04-23 15:13:53 +00:00
Bruno BELANYI 734f4452dd Rename fields in 'select_value'
This aligns with upstream, and makes more sense given their usage.
2024-04-23 15:12:55 +00:00
10 changed files with 2406 additions and 1608 deletions

View file

@ -35,10 +35,11 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
pub const FOLDS_QUERY: &'static str = include_str!("../../queries/folds.scm");
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
pub const INDENTS_QUERY: &'static str = include_str!("../../queries/indents.scm");
pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
#[cfg(test)]
mod tests {

View file

@ -1,8 +1,12 @@
function commaSeparated(elem) {
function commaSeparatedOptTrailing(elem) {
return seq(elem, repeat(seq(",", elem)), optional(","))
}
function trailingCommaSeparated(elem) {
function commaSeparatedNoTrailing(elem) {
return seq(elem, repeat(seq(",", elem)))
}
function commaSeparatedTrailing(elem) {
return repeat(seq(elem, ","))
}
@ -44,7 +48,7 @@ module.exports = grammar({
_old_module: ($) => seq(
field("type", $.identifier),
"{",
optional(commaSeparated(
optional(commaSeparatedOptTrailing(
alias(field("property", $._colon_property), $.property)
)),
"}",
@ -53,7 +57,7 @@ module.exports = grammar({
_new_module: ($) => seq(
field("type", $.identifier),
"(",
optional(commaSeparated(
optional(commaSeparatedOptTrailing(
alias(field("property", $._equal_property), $.property)
)),
")",
@ -127,28 +131,41 @@ module.exports = grammar({
")",
),
select_value: ($) => seq(
field("type", alias($.identifier, $.selection_type)),
select_value: ($) => choice(
$.condition,
seq("(", commaSeparatedOptTrailing($.condition), ")"),
),
condition: ($) => seq(
field("name", $.identifier),
"(",
field("condition", optional(commaSeparated($._string_literal))),
field("arguments", optional(commaSeparatedNoTrailing($._string_literal))),
")",
),
select_cases: ($) => seq(
"{",
optional(trailingCommaSeparated($.select_case)),
optional(commaSeparatedTrailing($.select_case)),
"}",
),
select_case: ($) => seq(
field("pattern", choice(
$._string_literal,
alias("default", $.default),
)),
field("pattern", $.select_pattern),
":",
field("value", $._case_value)
),
select_pattern: ($) => choice(
$._select_pattern,
seq("(", commaSeparatedOptTrailing($._select_pattern), ")"),
),
_select_pattern: ($) => choice(
$._string_literal,
$.boolean_literal,
alias("default", $.default),
),
_case_value: ($) => choice(
alias("unset", $.unset),
$._expr,
@ -156,13 +173,13 @@ module.exports = grammar({
list_expression: ($) => seq(
"[",
optional(commaSeparated(field("element", $._expr))),
optional(commaSeparatedOptTrailing(field("element", $._expr))),
"]",
),
map_expression: ($) => seq(
"{",
optional(commaSeparated(
optional(commaSeparatedOptTrailing(
alias(field("property", $._colon_property), $.property)
)),
"}",

View file

@ -43,6 +43,11 @@
"file-types": [
"bp"
],
"folds": "queries/folds.scm",
"highlights": "queries/highlights.scm",
"indents": "queries/indents.scm",
"injections": "queries/injections.scm",
"tags": "queries/tags.scm",
"injection-regex": "bp"
}
]

View file

@ -51,7 +51,8 @@
(unset)
(default)
] @variable.builtin
(selection_type) @function.builtin
(condition
name: (identifier) @function.builtin)
; }}}
; Expressions {{{

View file

@ -11,6 +11,16 @@
(select_expression
")" @indent.branch)
(select_value
"(" @indent.begin)
(select_value
")" @indent.branch)
; (select_pattern
; "(" @indent.begin)
; (select_pattern
; ")" @indent.branch)
(select_cases) @indent.begin
(select_cases
"}" @indent.branch)

183
src/grammar.json generated
View file

@ -487,19 +487,73 @@
]
},
"select_value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "condition"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "condition"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "condition"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"condition": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"name": "name",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "selection_type"
"type": "SYMBOL",
"name": "identifier"
}
},
{
@ -508,7 +562,7 @@
},
{
"type": "FIELD",
"name": "condition",
"name": "arguments",
"content": {
"type": "CHOICE",
"members": [
@ -534,18 +588,6 @@
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
@ -605,22 +647,8 @@
"type": "FIELD",
"name": "pattern",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
}
]
"type": "SYMBOL",
"name": "select_pattern"
}
},
{
@ -637,6 +665,87 @@
}
]
},
"select_pattern": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_select_pattern"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_select_pattern"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_select_pattern"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_select_pattern": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "SYMBOL",
"name": "boolean_literal"
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
}
]
},
"_case_value": {
"type": "CHOICE",
"members": [

114
src/node-types.json generated
View file

@ -177,6 +177,40 @@
"named": true,
"fields": {}
},
{
"type": "condition",
"named": true,
"fields": {
"arguments": {
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "integer_literal",
"named": true,
@ -354,15 +388,7 @@
"required": true,
"types": [
{
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"type": "select_pattern",
"named": true
}
]
@ -449,38 +475,46 @@
]
}
},
{
"type": "select_pattern",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
}
},
{
"type": "select_value",
"named": true,
"fields": {
"condition": {
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "selection_type",
"named": true
}
]
}
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "condition",
"named": true
}
]
}
},
{
@ -578,10 +612,6 @@
"type": "select",
"named": false
},
{
"type": "selection_type",
"named": true
},
{
"type": "true",
"named": false

3406
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -15,14 +15,17 @@ foo = select(release_variable("RELEASE_TEST"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(unset))))))
================================================================================
@ -42,15 +45,18 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(unset))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -72,20 +78,25 @@ foo = select(variant("arch"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -102,8 +113,9 @@ foo = select(variant("VARIANT"), {})
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)))
(select_cases))))
================================================================================
@ -126,23 +138,29 @@ foo = select(variant("VARIANT"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(unset))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))))))
================================================================================
@ -162,13 +180,16 @@ foo = select(variant(), {
(operator)
(select_expression
(select_value
(selection_type))
(condition
(identifier)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(unset))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
@ -188,14 +209,17 @@ foo = select(some_unknown_type("CONDITION"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
@ -215,15 +239,136 @@ foo = select(release_variable("ONE", "TWO"), {
(operator)
(select_expression
(select_value
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(condition
(identifier)
(interpreted_string_literal)
(interpreted_string_literal)))
(select_cases
(select_case
(interpreted_string_literal)
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(default)
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================
Select (trailing comma in arguments)
================================================================================
foo = select(some_boolean("VALUE",), {
true: "true",
false: "false",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)
(ERROR)))
(select_cases
(select_case
(select_pattern
(boolean_literal))
(interpreted_string_literal))
(select_case
(select_pattern
(boolean_literal))
(interpreted_string_literal))))))
================================================================================
Select (trailing comma in values)
================================================================================
foo = select((
arch(),
os(),
), {
(default, default): "true",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(condition
(identifier))
(condition
(identifier)))
(select_cases
(select_case
(select_pattern
(default)
(default))
(interpreted_string_literal))))))
================================================================================
Select (trailing comma in pattern)
================================================================================
foo = select((arch(), os()), {
(default, default,): "true",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(condition
(identifier))
(condition
(identifier)))
(select_cases
(select_case
(select_pattern
(default)
(default))
(interpreted_string_literal))))))
================================================================================
Select (boolean typed)
================================================================================
foo = select(some_boolean("IS_TRUE"), {
true: "true",
false: "false",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(select_pattern
(boolean_literal))
(interpreted_string_literal))
(select_case
(select_pattern
(boolean_literal))
(interpreted_string_literal))))))
================================================================================

View file

@ -26,3 +26,25 @@ foo = select(
default: 0,
}
)
foo = select((
arch(),
os(),
), {
(default, default): [],
})
foo = select(
(arch(), os()),
{
(default, default): [],
}
)
// We're really getting into more and more unlikely choices here...
foo = select((arch(), os()), {
(
default,
default,
): [],
})