Skip to content

Commit

Permalink
[language-c] C/C++ highlighting fixes…
Browse files Browse the repository at this point in the history
* GOTO labels
* Members like `foo.bar`
* Marking of constants in C++
  • Loading branch information
savetheclocktower committed Mar 18, 2024
1 parent 175174e commit a294c88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/language-c/grammars/tree-sitter-c/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

; PREPROCESSOR
; ============

Expand Down Expand Up @@ -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
; -------------------
Expand Down Expand Up @@ -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
; =========
Expand Down
14 changes: 13 additions & 1 deletion packages/language-c/grammars/tree-sitter-cpp/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
; -------------------

Expand Down Expand Up @@ -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*$"))
Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit a294c88

Please sign in to comment.