diff --git a/Cargo.toml b/Cargo.toml index 9ca884e..4707f77 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.3.0" +version = "0.2.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 551e7f9..2f4b0e3 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(alias($.default_case, $.select_case), ",")), + optional(seq($.default_case, ",")), "}", ), @@ -166,7 +166,7 @@ module.exports = grammar({ ), default_case: ($) => seq( - field("pattern", alias("default", $.default)), + field("pattern", "default"), ":", field("value", $._case_value), ), diff --git a/package.json b/package.json index 2788979..3c864d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-bp", - "version": "0.3.0", + "version": "0.2.0", "description": "Blueprint grammar for tree-sitter", "main": "bindings/node", "keywords": [ diff --git a/queries/highlights.scm b/queries/highlights.scm index 4209180..e548e18 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 2602bc0..482f27b 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -635,13 +635,8 @@ "type": "SEQ", "members": [ { - "type": "ALIAS", - "content": { - "type": "SYMBOL", - "name": "default_case" - }, - "named": true, - "value": "select_case" + "type": "SYMBOL", + "name": "default_case" }, { "type": "STRING", @@ -692,12 +687,7 @@ "type": "FIELD", "name": "pattern", "content": { - "type": "ALIAS", - "content": { - "type": "STRING", - "value": "default" - }, - "named": true, + "type": "STRING", "value": "default" } }, diff --git a/src/node-types.json b/src/node-types.json index e26beb4..1db28a2 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -177,6 +177,68 @@ "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, @@ -353,10 +415,6 @@ "multiple": false, "required": true, "types": [ - { - "type": "default", - "named": true - }, { "type": "interpreted_string_literal", "named": true @@ -423,6 +481,10 @@ "multiple": true, "required": false, "types": [ + { + "type": "default_case", + "named": true + }, { "type": "select_case", "named": true @@ -606,7 +668,7 @@ }, { "type": "default", - "named": true + "named": false }, { "type": "escape_sequence", diff --git a/src/parser.c b/src/parser.c index b33fb8a..f06de7f 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] = "select_case", + [sym_default_case] = "default_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_select_case, + [sym_default_case] = sym_default_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 = true, + .named = false, }, [anon_sym_unset] = { .visible = true, diff --git a/test/corpus/select.txt b/test/corpus/select.txt index ce291fd..fb76530 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -21,8 +21,7 @@ foo = select(release_variable("RELEASE_TEST"), { (select_case (interpreted_string_literal) (interpreted_string_literal)) - (select_case - (default) + (default_case (unset)))))) ================================================================================ @@ -136,8 +135,7 @@ foo = select(variant("VARIANT"), { (interpreted_string_literal) (interpreted_string_literal)) (ERROR - (select_case - (default) + (default_case (unset))) (select_case (interpreted_string_literal) @@ -169,8 +167,7 @@ foo = select(variant(), { (select_case (interpreted_string_literal) (unset)) - (select_case - (default) + (default_case (interpreted_string_literal)))))) ================================================================================ @@ -192,8 +189,7 @@ foo = select(some_unknown_type("CONDITION"), { (identifier) (identifier) (interpreted_string_literal) - (interpreted_string_literal) - (default)) + (interpreted_string_literal)) (interpreted_string_literal)) (ERROR))