Debian Codegraph @

runtime/queries/cpp/highlights.scm

raw symbols SCIP
1 ; inherits: c
2
3 ; Constants
4
5 (this) @variable.builtin
6 (null) @constant.builtin
7
8 ; Types
9
10 (using_declaration ("using" "namespace" (identifier) @namespace))
11 (using_declaration ("using" "namespace" (qualified_identifier name: (identifier) @namespace)))
12 ; Only a Capitalised qualified leaf (`Color::Red`) is an enum variant; a
13 ; lowercase one (`std::cout`) is a value/member and falls through to @variable.
14 ((qualified_identifier name: (identifier) @type.enum.variant)
15 (#match? @type.enum.variant "^[A-Z]"))
16 ; C colours enumerator definitions @constant (see c/highlights.scm); C++ resolves
17 ; enum values through the qualified path above as @type.enum.variant, so keep the
18 ; definition matching that.
19 (enumerator name: (identifier) @type.enum.variant)
20 (namespace_definition name: (namespace_identifier) @namespace)
21 (namespace_identifier) @namespace
22
23 ; Type-introducing declarations
24 (concept_definition name: (identifier) @type.definition)
25 (alias_declaration name: (type_identifier) @type.definition)
26
27 (auto) @type.builtin
28
29 (ref_qualifier ["&" "&&"] @type.builtin)
30 (reference_declarator ["&" "&&"] @type.builtin)
31 (abstract_reference_declarator ["&" "&&"] @type.builtin)
32
33 ; -------
34 ; Functions
35 ; -------
36 ; Support up to 4 levels of nesting of qualifiers
37 ; i.e. a::b::c::d::func();
38 (call_expression
39 function: (qualified_identifier
40 name: (identifier) @function))
41 (call_expression
42 function: (qualified_identifier
43 name: (qualified_identifier
44 name: (identifier) @function)))
45 (call_expression
46 function: (qualified_identifier
47 name: (qualified_identifier
48 name: (qualified_identifier
49 name: (identifier) @function))))
50 (call_expression
51 function: (qualified_identifier
52 name: (qualified_identifier
53 name: (qualified_identifier
54 name: (qualified_identifier
55 name: (identifier) @function)))))
56
57 (template_function
58 name: (identifier) @function)
59
60 (template_method
61 name: (field_identifier) @function)
62
63 ; Support up to 4 levels of nesting of qualifiers
64 ; i.e. a::b::c::d::func();
65 (function_declarator
66 declarator: (qualified_identifier
67 name: (identifier) @function))
68 (function_declarator
69 declarator: (qualified_identifier
70 name: (qualified_identifier
71 name: (identifier) @function)))
72 (function_declarator
73 declarator: (qualified_identifier
74 name: (qualified_identifier
75 name: (qualified_identifier
76 name: (identifier) @function))))
77 (function_declarator
78 declarator: (qualified_identifier
79 name: (qualified_identifier
80 name: (qualified_identifier
81 name: (qualified_identifier
82 name: (identifier) @function)))))
83
84 (function_declarator
85 declarator: (field_identifier) @function)
86
87 ; Constructors
88
89 (class_specifier
90 (type_identifier) @type
91 (field_declaration_list
92 (function_definition
93 (function_declarator
94 (identifier) @constructor)))
95 (#eq? @type @constructor))
96 (destructor_name "~" @constructor
97 (identifier) @constructor)
98
99 ; Parameters
100
101 (parameter_declaration
102 declarator: (reference_declarator (identifier) @variable.parameter))
103 (optional_parameter_declaration
104 declarator: (identifier) @variable.parameter)
105
106 ; Keywords
107
108 (template_argument_list (["<" ">"] @punctuation.bracket))
109 (template_parameter_list (["<" ">"] @punctuation.bracket))
110 (default_method_clause "default" @keyword)
111
112 "static_assert" @function.special
113
114 [
115 "<=>"
116 "[]"
117 "()"
118 "^^" ; C++26 reflection operator (reflect_expression)
119 ] @operator
120
121 ; C++26 splice brackets `[: reflection :]` (splice_specifier / splice_type_specifier).
122 (splice_specifier ["[:" ":]"] @punctuation.bracket)
123
124
125 ; These casts are parsed as function calls, but are not.
126 ((identifier) @keyword (#eq? @keyword "static_cast"))
127 ((identifier) @keyword (#eq? @keyword "dynamic_cast"))
128 ((identifier) @keyword (#eq? @keyword "reinterpret_cast"))
129 ((identifier) @keyword (#eq? @keyword "const_cast"))
130
131 [
132 "co_await"
133 "co_return"
134 "co_yield"
135 "concept"
136 "delete"
137 "new"
138 "operator"
139 "requires"
140 "using"
141 ] @keyword
142
143 [
144 "catch"
145 "noexcept"
146 "throw"
147 "try"
148 ] @keyword.control.exception
149
150
151 [
152 "and"
153 "and_eq"
154 "bitor"
155 "bitand"
156 "not"
157 "not_eq"
158 "or"
159 "or_eq"
160 "xor"
161 "xor_eq"
162 ] @keyword.operator
163
164 [
165 "class"
166 "namespace"
167 "typename"
168 "template"
169 ] @keyword.storage.type
170
171 [
172 "constexpr"
173 "constinit"
174 "consteval"
175 "mutable"
176 ] @keyword.storage.modifier
177
178 ; Modifiers that aren't plausibly type/storage related.
179 [
180 "decltype"
181 "explicit"
182 "friend"
183 "virtual"
184 (virtual_specifier) ; override/final
185 "private"
186 "protected"
187 "public"
188 "inline" ; C++ meaning differs from C!
189 ] @keyword
190
191 ; Strings
192
193 (raw_string_literal) @string