Skip to content

Commit

Permalink
c/c++ highlighting: various tweaks
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
sam-mccall authored and the-mikedavis committed Oct 15, 2022
1 parent a3ed916 commit aef37d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 3 additions & 5 deletions runtime/queries/c/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
] @keyword.storage.type

[
"const"
"extern"
"inline"
"register"
"volatile"
(type_qualifier)
(storage_class_specifier)
] @keyword.storage.modifier

Expand Down Expand Up @@ -107,7 +105,7 @@
(system_lib_string) @string

(null) @constant
(number_literal) @constant.numeric.integer
(number_literal) @constant.numeric
(char_literal) @constant.character

(call_expression
Expand All @@ -133,7 +131,7 @@
(statement_identifier) @label
(type_identifier) @type
(primitive_type) @type.builtin
(sized_type_specifier) @type
(sized_type_specifier) @type.builtin

((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
Expand Down
22 changes: 16 additions & 6 deletions runtime/queries/cpp/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
; Functions

; These casts are parsed as function calls, but are not.
((identifier) @keyword (#eq? @keyword "static_cast"))
((identifier) @keyword (#eq? @keyword "dynamic_cast"))
((identifier) @keyword (#eq? @keyword "reinterpret_cast"))
((identifier) @keyword (#eq? @keyword "const_cast"))

(call_expression
function: (qualified_identifier
name: (identifier) @function))
Expand Down Expand Up @@ -63,7 +69,6 @@
"co_yield"
"concept"
"delete"
"final"
"new"
"operator"
"requires"
Expand Down Expand Up @@ -95,22 +100,27 @@
"class"
"namespace"
"typename"
"template"
] @keyword.storage.type

[
"constexpr"
"constinit"
"consteval"
"mutable"
] @keyword.storage.modifier

; Modifiers that aren't plausibly type/storage related.
[
"explicit"
"friend"
"mutable"
"virtual"
(virtual_specifier) ; override/final
"private"
"protected"
"public"
"override"
"template"
"virtual"
] @keyword.storage.modifier
"inline" ; C++ meaning differs from C!
] @keyword

; Strings

Expand Down

0 comments on commit aef37d4

Please sign in to comment.