[language-c] C/C++ highlighting fixes…

* GOTO labels
* Members like `foo.bar`
* Marking of constants in C++
This commit is contained in:
Andrew Dupont 2024-03-17 20:49:17 -07:00
parent 175174e05c
commit a294c88a47
2 changed files with 27 additions and 2 deletions

View File

@ -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
; =========

View File

@ -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))