From ba2022d3c8a3e8a23db3f2c3778e7b9aa51798d6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 8 Apr 2024 22:13:23 +0100 Subject: [PATCH 1/4] Add builtins highlighting --- queries/highlights.scm | 8 ++++++++ test/highlight/builtins.bp | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/highlight/builtins.bp diff --git a/queries/highlights.scm b/queries/highlights.scm index b4cc660..7422e6f 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -49,6 +49,14 @@ field: (identifier) @variable.member)) ; }}} +; Built-ins {{{ +[ + (unset) + "default" +] @variable.builtin +(selection_type) @function.builtin +; }}} + ; Expressions {{{ (map_expression (property diff --git a/test/highlight/builtins.bp b/test/highlight/builtins.bp new file mode 100644 index 0000000..508a8ed --- /dev/null +++ b/test/highlight/builtins.bp @@ -0,0 +1,14 @@ +foo = select(soong_config_variable("my_namespace", "my_var"), { + // ^ function.builtin + "foo": unset, + // ^ variable.builtin + default: select(variant("VARIANT") {}), + // <- variable.builtin + // ^ function.builtin +}) + +/* Assigning to builtins is conveniently not allowed at runtime */ +unset = 12 +// <- variable.builtin +default = 27 +// <- variable.builtin From 73b0797891390e36f0cf10122f4df40ae1dffa52 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 8 Apr 2024 22:13:23 +0100 Subject: [PATCH 2/4] Add builtins highlighting --- queries/highlights.scm | 8 ++++++++ test/highlight/builtins.bp | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/highlight/builtins.bp diff --git a/queries/highlights.scm b/queries/highlights.scm index b4cc660..7422e6f 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -49,6 +49,14 @@ field: (identifier) @variable.member)) ; }}} +; Built-ins {{{ +[ + (unset) + "default" +] @variable.builtin +(selection_type) @function.builtin +; }}} + ; Expressions {{{ (map_expression (property diff --git a/test/highlight/builtins.bp b/test/highlight/builtins.bp new file mode 100644 index 0000000..73b32e3 --- /dev/null +++ b/test/highlight/builtins.bp @@ -0,0 +1,8 @@ +foo = select(soong_config_variable("my_namespace", "my_var"), { + // ^ function.builtin + "foo": unset, + // ^ variable.builtin + default: select(variant("VARIANT"), {}), + // <- variable.builtin + // ^ function.builtin +}) From be1e3f07d3099756026300c4e0fa2edf994d79af Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 8 Apr 2024 09:49:16 +0000 Subject: [PATCH 3/4] Make 'line_comment' more explicit about newlines Because of the way regular expressions work, they were already bounded at newlines here, but explicit is better than implicit :-). --- grammar.js | 2 +- src/grammar.json | 2 +- test/corpus/comments.txt | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index 86d0dd6..929f36e 100644 --- a/grammar.js +++ b/grammar.js @@ -23,7 +23,7 @@ module.exports = grammar({ $.module, ), - line_comment: (_) => seq("//", /.*/), + line_comment: (_) => seq("//", /[^\n]*/), block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'), diff --git a/src/grammar.json b/src/grammar.json index c9b0e32..2ac5436 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -30,7 +30,7 @@ }, { "type": "PATTERN", - "value": ".*" + "value": "[^\\n]*" } ] }, diff --git a/test/corpus/comments.txt b/test/corpus/comments.txt index 5304a7e..6c91a89 100644 --- a/test/corpus/comments.txt +++ b/test/corpus/comments.txt @@ -85,6 +85,23 @@ Block comment with asterisks -------------------------------------------------------------------------------- +(source_file + (block_comment)) + +================================================================================ +Block comment (multiline) +================================================================================ + +/* + This + is + a + long + comment +*/ + +-------------------------------------------------------------------------------- + (source_file (block_comment)) From f6e1266493d4819eec508a7a2727ca39a4efd45e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 10 Apr 2024 15:21:07 +0000 Subject: [PATCH 4/4] Consider module as function call for highlighting Their semantic is closer to a function call (like i.e: Bazel rules) rather than a module/namespace. Similarly for their properties, which are more like parameters than members. --- queries/highlights.scm | 4 ++-- test/highlight/modules.bp | 16 ++++++++-------- test/highlight/properties.bp | 2 +- test/highlight/select.bp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/queries/highlights.scm b/queries/highlights.scm index 7422e6f..17c5692 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -42,11 +42,11 @@ (identifier) @variable (module - type: (identifier) @module) + type: (identifier) @function.call) (module (property - field: (identifier) @variable.member)) + field: (identifier) @variable.parameter)) ; }}} ; Built-ins {{{ diff --git a/test/highlight/modules.bp b/test/highlight/modules.bp index 248acdf..e115e6a 100644 --- a/test/highlight/modules.bp +++ b/test/highlight/modules.bp @@ -1,21 +1,21 @@ foo {} -// <- module +// <- function.call foo () -// <- module +// <- function.call foo { -// <- module +// <- function.call field: 12, - // <- variable.member + // <- variable.parameter another_field: 27, - // <- variable.member + // <- variable.parameter } foo ( -// <- module +// <- function.call field = 42, - // <- variable.member + // <- variable.parameter done = false, - // <- variable.member + // <- variable.parameter ) diff --git a/test/highlight/properties.bp b/test/highlight/properties.bp index 6bc97ef..8ad2c55 100644 --- a/test/highlight/properties.bp +++ b/test/highlight/properties.bp @@ -1,6 +1,6 @@ foo { field: { - // <- variable.member + // <- variable.parameter key: 42, // <- property }, diff --git a/test/highlight/select.bp b/test/highlight/select.bp index 831608d..b857c1e 100644 --- a/test/highlight/select.bp +++ b/test/highlight/select.bp @@ -11,5 +11,5 @@ select = 42 // Or module property foo { select: 42, - // <- variable.member + // <- variable.parameter }