on master help sign in
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

commitaef37d43d7a943fdf58ade7df4d8defbef9a7ce0 authorSam McCall <sam.mccall@gmail.com> dateSat 15 Oct 2022, 01:01 (4 years ago) parenta3ed916
2 files changed+19−11
runtime/queries/c/highlights.scm+3−5 runtime/queries/cpp/highlights.scm+16−6
runtime/queries/c/highlights.scm+3−5
@@ -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+16−6
@@ -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