From 8db7b053f541e54bcdec725667ee1267df8ab135 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 9 Apr 2024 13:08:02 +0100 Subject: [PATCH 1/3] Add 'default' alias This makes it appear in the tree as a named node. --- grammar.js | 2 +- queries/highlights.scm | 2 +- src/grammar.json | 7 ++++++- src/node-types.json | 4 ++-- src/parser.c | 2 +- test/corpus/select.txt | 6 +++++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/grammar.js b/grammar.js index 2f4b0e3..6c4b1e8 100644 --- a/grammar.js +++ b/grammar.js @@ -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/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..3df0aa5 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -687,7 +687,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..acafc16 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -187,7 +187,7 @@ "types": [ { "type": "default", - "named": false + "named": true } ] }, @@ -668,7 +668,7 @@ }, { "type": "default", - "named": false + "named": true }, { "type": "escape_sequence", diff --git a/src/parser.c b/src/parser.c index f06de7f..82f9ccf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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..c9c0233 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -22,6 +22,7 @@ foo = select(release_variable("RELEASE_TEST"), { (interpreted_string_literal) (interpreted_string_literal)) (default_case + (default) (unset)))))) ================================================================================ @@ -136,6 +137,7 @@ foo = select(variant("VARIANT"), { (interpreted_string_literal)) (ERROR (default_case + (default) (unset))) (select_case (interpreted_string_literal) @@ -168,6 +170,7 @@ foo = select(variant(), { (interpreted_string_literal) (unset)) (default_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)) From e6a2757c5175a6dcdb1d5478d245bd9601e0376e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 9 Apr 2024 13:09:48 +0100 Subject: [PATCH 2/3] Alias 'default_case' to 'select_case' There's not much use in the node being a different name. --- grammar.js | 2 +- src/grammar.json | 9 ++++-- src/node-types.json | 70 +++--------------------------------------- src/parser.c | 4 +-- test/corpus/select.txt | 6 ++-- 5 files changed, 17 insertions(+), 74 deletions(-) diff --git a/grammar.js b/grammar.js index 6c4b1e8..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), ",")), "}", ), diff --git a/src/grammar.json b/src/grammar.json index 3df0aa5..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", diff --git a/src/node-types.json b/src/node-types.json index acafc16..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": true - } - ] - }, - "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 diff --git a/src/parser.c b/src/parser.c index 82f9ccf..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, diff --git a/test/corpus/select.txt b/test/corpus/select.txt index c9c0233..ce291fd 100644 --- a/test/corpus/select.txt +++ b/test/corpus/select.txt @@ -21,7 +21,7 @@ foo = select(release_variable("RELEASE_TEST"), { (select_case (interpreted_string_literal) (interpreted_string_literal)) - (default_case + (select_case (default) (unset)))))) @@ -136,7 +136,7 @@ foo = select(variant("VARIANT"), { (interpreted_string_literal) (interpreted_string_literal)) (ERROR - (default_case + (select_case (default) (unset))) (select_case @@ -169,7 +169,7 @@ foo = select(variant(), { (select_case (interpreted_string_literal) (unset)) - (default_case + (select_case (default) (interpreted_string_literal)))))) From 6ece5d984a456b9308aa4446f2afd4a085cf9803 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 13 Apr 2024 18:27:56 +0100 Subject: [PATCH 3/3] Release 0.3.0 --- Cargo.toml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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": [