diff --git a/Cargo.toml b/Cargo.toml index 4707f77..9ca884e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-bp" description = "Blueprint grammar for the tree-sitter parsing library" -version = "0.2.0" +version = "0.3.0" keywords = ["incremental", "parsing", "android", "blueprint"] categories = ["parsing", "text-editors"] repository = "https://git.belanyi.fr/ambroisie/tree-sitter-bp" diff --git a/grammar.js b/grammar.js index 2f4b0e3..551e7f9 100644 --- a/grammar.js +++ b/grammar.js @@ -155,7 +155,7 @@ module.exports = grammar({ "{", optional(trailingCommaSeparated($.select_case)), // default *must* be the last one, enforced at parse-time... - optional(seq($.default_case, ",")), + optional(seq(alias($.default_case, $.select_case), ",")), "}", ), @@ -166,7 +166,7 @@ module.exports = grammar({ ), default_case: ($) => seq( - field("pattern", "default"), + field("pattern", alias("default", $.default)), ":", field("value", $._case_value), ), diff --git a/package.json b/package.json index 3c864d0..2788979 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-bp", - "version": "0.2.0", + "version": "0.3.0", "description": "Blueprint grammar for tree-sitter", "main": "bindings/node", "keywords": [ diff --git a/queries/highlights.scm b/queries/highlights.scm index e548e18..4209180 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -49,7 +49,7 @@ ; Built-ins {{{ [ (unset) - "default" + (default) ] @variable.builtin (selection_type) @function.builtin ; }}} diff --git a/src/grammar.json b/src/grammar.json index 482f27b..2602bc0 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -635,8 +635,13 @@ "type": "SEQ", "members": [ { - "type": "SYMBOL", - "name": "default_case" + "type": "ALIAS", + "content": { + "type": "SYMBOL", + "name": "default_case" + }, + "named": true, + "value": "select_case" }, { "type": "STRING", @@ -687,7 +692,12 @@ "type": "FIELD", "name": "pattern", "content": { - "type": "STRING", + "type": "ALIAS", + "content": { + "type": "STRING", + "value": "default" + }, + "named": true, "value": "default" } }, diff --git a/src/node-types.json b/src/node-types.json index 1db28a2..e26beb4 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -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, @@ -415,6 +353,10 @@ "multiple": false, "required": true, "types": [ + { + "type": "default", + "named": true + }, { "type": "interpreted_string_literal", "named": true @@ -481,10 +423,6 @@ "multiple": true, "required": false, "types": [ - { - "type": "default_case", - "named": true - }, { "type": "select_case", "named": true @@ -668,7 +606,7 @@ }, { "type": "default", - "named": false + "named": true }, { "type": "escape_sequence", diff --git a/src/parser.c b/src/parser.c index f06de7f..b33fb8a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -134,7 +134,7 @@ static const char * const ts_symbol_names[] = { [sym_soong_config_variable] = "soong_config_variable", [sym_select_cases] = "select_cases", [sym_select_case] = "select_case", - [sym_default_case] = "default_case", + [sym_default_case] = "select_case", [sym__case_value] = "_case_value", [sym_list_expression] = "list_expression", [sym_map_expression] = "map_expression", @@ -201,7 +201,7 @@ static const TSSymbol ts_symbol_map[] = { [sym_soong_config_variable] = sym_soong_config_variable, [sym_select_cases] = sym_select_cases, [sym_select_case] = sym_select_case, - [sym_default_case] = sym_default_case, + [sym_default_case] = sym_select_case, [sym__case_value] = sym__case_value, [sym_list_expression] = sym_list_expression, [sym_map_expression] = sym_map_expression, @@ -335,7 +335,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }, [anon_sym_default] = { .visible = true, - .named = false, + .named = true, }, [anon_sym_unset] = { .visible = true, diff --git a/test/corpus/select.txt b/test/corpus/select.txt index fb76530..ce291fd 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -21,7 +21,8 @@ foo = select(release_variable("RELEASE_TEST"), { (select_case (interpreted_string_literal) (interpreted_string_literal)) - (default_case + (select_case + (default) (unset)))))) ================================================================================ @@ -135,7 +136,8 @@ foo = select(variant("VARIANT"), { (interpreted_string_literal) (interpreted_string_literal)) (ERROR - (default_case + (select_case + (default) (unset))) (select_case (interpreted_string_literal) @@ -167,7 +169,8 @@ foo = select(variant(), { (select_case (interpreted_string_literal) (unset)) - (default_case + (select_case + (default) (interpreted_string_literal)))))) ================================================================================ @@ -189,7 +192,8 @@ foo = select(some_unknown_type("CONDITION"), { (identifier) (identifier) (interpreted_string_literal) - (interpreted_string_literal)) + (interpreted_string_literal) + (default)) (interpreted_string_literal)) (ERROR))