Compare commits

..

No commits in common. "aa06bb8b9ffbf4bea8a1edfc453aa447dcafaeb7" and "c56e2eca70eb58816321464d2156ee906c4b3bc9" have entirely different histories.

10 changed files with 1572 additions and 2370 deletions

View file

@ -35,11 +35,10 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
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");
// 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");
#[cfg(test)]
mod tests {

View file

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

View file

@ -43,11 +43,6 @@
"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,8 +51,7 @@
(unset)
(default)
] @variable.builtin
(condition
name: (identifier) @function.builtin)
(selection_type) @function.builtin
; }}}
; Expressions {{{

View file

@ -11,16 +11,6 @@
(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,73 +487,19 @@
]
},
"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": "name",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "selection_type"
}
},
{
@ -562,7 +508,7 @@
},
{
"type": "FIELD",
"name": "arguments",
"name": "condition",
"content": {
"type": "CHOICE",
"members": [
@ -588,6 +534,18 @@
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
@ -647,8 +605,22 @@
"type": "FIELD",
"name": "pattern",
"content": {
"type": "SYMBOL",
"name": "select_pattern"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "default"
},
"named": true,
"value": "default"
}
]
}
},
{
@ -665,87 +637,6 @@
}
]
},
"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,40 +177,6 @@
"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,
@ -388,7 +354,15 @@
"required": true,
"types": [
{
"type": "select_pattern",
"type": "default",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "raw_string_literal",
"named": true
}
]
@ -475,46 +449,38 @@
]
}
},
{
"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": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "condition",
"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
}
]
}
}
},
{
@ -612,6 +578,10 @@
"type": "select",
"named": false
},
{
"type": "selection_type",
"named": true
},
{
"type": "true",
"named": false

3332
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -15,17 +15,14 @@ foo = select(release_variable("RELEASE_TEST"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(default))
(default)
(unset))))))
================================================================================
@ -45,18 +42,15 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(unset))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))))))
================================================================================
@ -78,25 +72,20 @@ foo = select(variant("arch"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))))))
================================================================================
@ -113,9 +102,8 @@ foo = select(variant("VARIANT"), {})
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal))
(select_cases))))
================================================================================
@ -138,29 +126,23 @@ foo = select(variant("VARIANT"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(default))
(default)
(unset))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))))))
================================================================================
@ -180,16 +162,13 @@ foo = select(variant(), {
(operator)
(select_expression
(select_value
(condition
(identifier)))
(selection_type))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(unset))
(select_case
(select_pattern
(default))
(default)
(interpreted_string_literal))))))
================================================================================
@ -209,17 +188,14 @@ foo = select(some_unknown_type("CONDITION"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(selection_type)
(interpreted_string_literal))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal)
(interpreted_string_literal))
(select_case
(select_pattern
(default))
(default)
(interpreted_string_literal))))))
================================================================================
@ -239,136 +215,15 @@ foo = select(release_variable("ONE", "TWO"), {
(operator)
(select_expression
(select_value
(condition
(identifier)
(selection_type)
(interpreted_string_literal)
(interpreted_string_literal))
(select_cases
(select_case
(interpreted_string_literal)
(interpreted_string_literal)))
(select_cases
(select_case
(select_pattern
(interpreted_string_literal))
(interpreted_string_literal))
(select_case
(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))
(default)
(interpreted_string_literal))))))
================================================================================

View file

@ -26,25 +26,3 @@ 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,
): [],
})