From aef37d43d7a943fdf58ade7df4d8defbef9a7ce0 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Sat, 15 Oct 2022 01:01:11 +0200 Subject: 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 --- runtime/queries/c/highlights.scm | 8 +++----- runtime/queries/cpp/highlights.scm | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index fe5dacaf..8122216d 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -8,11 +8,9 @@ ] @keyword.storage.type [ - "const" "extern" - "inline" "register" - "volatile" + (type_qualifier) (storage_class_specifier) ] @keyword.storage.modifier @@ -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 @@ -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_]*$")) diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm index 7bfccf72..8637489e 100644 --- a/runtime/queries/cpp/highlights.scm +++ b/runtime/queries/cpp/highlights.scm @@ -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)) @@ -63,7 +69,6 @@ "co_yield" "concept" "delete" - "final" "new" "operator" "requires" @@ -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 -- cgit v1.2.3-70-g09d2