From a294c88a47fb2d3a5ddc560392b8efeb48b285c2 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sun, 17 Mar 2024 20:49:17 -0700 Subject: [PATCH] =?UTF-8?q?[language-c]=20C/C++=20highlighting=20fixes?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * GOTO labels * Members like `foo.bar` * Marking of constants in C++ --- .../grammars/tree-sitter-c/highlights.scm | 15 ++++++++++++++- .../grammars/tree-sitter-cpp/highlights.scm | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/language-c/grammars/tree-sitter-c/highlights.scm b/packages/language-c/grammars/tree-sitter-c/highlights.scm index 344340d1e..1a5a73ebd 100644 --- a/packages/language-c/grammars/tree-sitter-c/highlights.scm +++ b/packages/language-c/grammars/tree-sitter-c/highlights.scm @@ -1,4 +1,3 @@ - ; PREPROCESSOR ; ============ @@ -223,6 +222,14 @@ field: (field_identifier) @variable.other.member.assignment.c) (#set! capture.final)) +; Goto label definitions: the "foo" in `foo:` before a statement. +(labeled_statement + label: (statement_identifier) @entity.name.label.c) + +; Goto statements — the "foo" in `goto foo;` +(goto_statement + label: (statement_identifier) @support.other.label.c) + ; Function parameters ; ------------------- @@ -256,6 +263,12 @@ "->" field: (field_identifier) @variable.other.member.c) +; The "bar" in `foo.bar`. +(field_expression + operator: "." + field: (field_identifier) @variable.other.member.c) + + ; FUNCTIONS ; ========= diff --git a/packages/language-c/grammars/tree-sitter-cpp/highlights.scm b/packages/language-c/grammars/tree-sitter-cpp/highlights.scm index ef65e50a4..5af781710 100644 --- a/packages/language-c/grammars/tree-sitter-cpp/highlights.scm +++ b/packages/language-c/grammars/tree-sitter-cpp/highlights.scm @@ -305,6 +305,13 @@ (identifier) @variable.declaration.cpp) (#is-not? test.descendantOfType parameter_declaration)) +; Goto label definitions like `foo:` before a statement. +(labeled_statement + label: (statement_identifier) @entity.name.label.cpp) + +(goto_statement + label: (statement_identifier) @support.other.label.cpp) + ; Function parameters ; ------------------- @@ -341,6 +348,11 @@ "->" field: (field_identifier) @variable.other.member.cpp) +; The "bar" in `foo.bar`. +(field_expression + operator: "." + field: (field_identifier) @variable.other.member.cpp) + ; Common naming idiom for C++ instanced vars: "fMemberName" ; ((identifier) @variable.other.readwrite.member.cpp ; (#match? @variable.other.readwrite.member.cpp "^(f|m)[A-Z]\\w*$")) @@ -372,7 +384,7 @@ ; macro preprocessors. The convention is decently strong in C/C++ that all-caps ; identifiers will refer to `#define`d things. ((identifier) @constant.other.cpp - (#match? @constant.other.cpp "[_A-Z][_A-Z0-9]*$") + (#match? @constant.other.cpp "^[_A-Z][_A-Z0-9]*$") (#set! capture.shy))