Skip to content

Commit aef37d4

Browse files
sam-mccallthe-mikedavis
authored andcommitted
c/c++ highlighting: various tweaks
- treat `restrict`/`_Atomic` like `const`/`volatile` => @Keyword.storage.modifier - highlight `unsigned int` as builtin => @type.builtin - recognize `static_cast` and friends => @Keyword - `template` is a kind of entity like `typename` => @Keyword.storage.type - many declaration modifiers have nothing to do with storage/types (explicit, friend, access specifiers, inline in C++) => @Keyword - fix floats highlighted as integer => @constant.numeric
1 parent a3ed916 commit aef37d4

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

runtime/queries/c/highlights.scm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
] @keyword.storage.type
99

1010
[
11-
"const"
1211
"extern"
13-
"inline"
1412
"register"
15-
"volatile"
13+
(type_qualifier)
1614
(storage_class_specifier)
1715
] @keyword.storage.modifier
1816

@@ -107,7 +105,7 @@
107105
(system_lib_string) @string
108106

109107
(null) @constant
110-
(number_literal) @constant.numeric.integer
108+
(number_literal) @constant.numeric
111109
(char_literal) @constant.character
112110

113111
(call_expression
@@ -133,7 +131,7 @@
133131
(statement_identifier) @label
134132
(type_identifier) @type
135133
(primitive_type) @type.builtin
136-
(sized_type_specifier) @type
134+
(sized_type_specifier) @type.builtin
137135

138136
((identifier) @constant
139137
(#match? @constant "^[A-Z][A-Z\\d_]*$"))

runtime/queries/cpp/highlights.scm

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
; Functions
22

3+
; These casts are parsed as function calls, but are not.
4+
((identifier) @keyword (#eq? @keyword "static_cast"))
5+
((identifier) @keyword (#eq? @keyword "dynamic_cast"))
6+
((identifier) @keyword (#eq? @keyword "reinterpret_cast"))
7+
((identifier) @keyword (#eq? @keyword "const_cast"))
8+
39
(call_expression
410
function: (qualified_identifier
511
name: (identifier) @function))
@@ -63,7 +69,6 @@
6369
"co_yield"
6470
"concept"
6571
"delete"
66-
"final"
6772
"new"
6873
"operator"
6974
"requires"
@@ -95,22 +100,27 @@
95100
"class"
96101
"namespace"
97102
"typename"
103+
"template"
98104
] @keyword.storage.type
99105

100106
[
101107
"constexpr"
102108
"constinit"
103109
"consteval"
110+
"mutable"
111+
] @keyword.storage.modifier
112+
113+
; Modifiers that aren't plausibly type/storage related.
114+
[
104115
"explicit"
105116
"friend"
106-
"mutable"
117+
"virtual"
118+
(virtual_specifier) ; override/final
107119
"private"
108120
"protected"
109121
"public"
110-
"override"
111-
"template"
112-
"virtual"
113-
] @keyword.storage.modifier
122+
"inline" ; C++ meaning differs from C!
123+
] @keyword
114124

115125
; Strings
116126

0 commit comments

Comments
 (0)