From 8db7b053f541e54bcdec725667ee1267df8ab135 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 9 Apr 2024 13:08:02 +0100 Subject: [PATCH] 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))