Debian Codegraph @

runtime/queries/swift/highlights.scm

raw symbols SCIP
1 ; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/7b7909f2f6b9414be0958275f4c8e5d69c3bca43/queries/highlights.scm
2
3 ; Typed throws (SE-0413), `func f() throws(MyError)`: the `throws` keyword is a
4 ; hidden token inside `throws_clause`, so it has no node of its own to capture.
5 ; Capturing the whole clause as a base layer up here, before the punctuation and
6 ; type rules below, leaves only the bare `throws` word coloured: the parens fall
7 ; back to @punctuation.bracket and the error type to @type via those later, more
8 ; specific rules.
9 (throws_clause) @keyword
10
11 (line_string_literal
12 ["\\(" ")"] @punctuation.special)
13
14 ["." ";" ":" "," ] @punctuation.delimiter
15 ["(" ")" "[" "]" "{" "}" "<" ">"] @punctuation.bracket
16
17 ; Operators
18 [
19 "!"
20 "?"
21 "+"
22 "-"
23 "\\"
24 "*"
25 "/"
26 "%"
27 "="
28 "+="
29 "-="
30 "*="
31 "/="
32 "<"
33 ">"
34 "<="
35 ">="
36 "++"
37 "--"
38 "&"
39 "~"
40 "%="
41 "!="
42 "!=="
43 "=="
44 "==="
45 "??"
46
47 "->"
48
49 "..<"
50 "..."
51 (custom_operator)
52 ] @operator
53
54 "?" @type
55 (type_annotation "!" @type)
56
57 ; Identifiers
58 (simple_identifier) @variable
59 (attribute) @variable
60 (type_identifier) @type
61 (self_expression) @variable.builtin
62 (user_type (type_identifier) @variable.builtin (#eq? @variable.builtin "Self"))
63
64 ; Declarations
65 "func" @keyword.function
66 [
67 (visibility_modifier)
68 (member_modifier)
69 (function_modifier)
70 (property_modifier)
71 (parameter_modifier)
72 (inheritance_modifier)
73 ] @keyword
74
75 (function_declaration (simple_identifier) @function.method)
76 (protocol_function_declaration (simple_identifier) @function.method)
77 (init_declaration ["init" @constructor])
78 (deinit_declaration ["deinit" @constructor])
79
80 (throws) @keyword
81 "async" @keyword
82 "await" @keyword
83 (where_keyword) @keyword
84 (parameter external_name: (simple_identifier) @variable.parameter)
85 (parameter name: (simple_identifier) @variable.parameter)
86 (type_parameter (type_identifier) @variable.parameter)
87 (inheritance_constraint (identifier (simple_identifier) @variable.parameter))
88 (equality_constraint (identifier (simple_identifier) @variable.parameter))
89 (pattern bound_identifier: (simple_identifier)) @variable
90
91 [
92 "typealias"
93 "struct"
94 "class"
95 "actor"
96 "enum"
97 "protocol"
98 "extension"
99 "indirect"
100 "nonisolated"
101 "override"
102 "convenience"
103 "required"
104 "mutating"
105 "associatedtype"
106 "package"
107 "any"
108 ] @keyword
109
110 (opaque_type ["some" @keyword])
111 (existential_type ["any" @keyword])
112
113 (precedence_group_declaration
114 ["precedencegroup" @keyword]
115 (simple_identifier) @type)
116 (precedence_group_attribute
117 (simple_identifier) @keyword
118 [(simple_identifier) @type
119 (boolean_literal) @constant.builtin.boolean])
120
121 [
122 (getter_specifier)
123 (setter_specifier)
124 (modify_specifier)
125 ] @keyword
126
127 (class_body (property_declaration (pattern (simple_identifier) @variable.other.member)))
128 (protocol_property_declaration (pattern (simple_identifier) @variable.other.member))
129
130 (import_declaration "import" @keyword.control.import)
131
132 (enum_entry "case" @keyword)
133
134 ; Member access
135 (navigation_suffix
136 (simple_identifier) @variable.other.member)
137
138 ; Function calls
139 (call_expression (simple_identifier) @function) ; foo()
140 (call_expression ; foo.bar.baz(): highlight the baz()
141 (navigation_expression
142 (navigation_suffix (simple_identifier) @function)))
143 ((navigation_expression
144 (simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
145 (#match? @type "^[A-Z]"))
146 (call_expression (simple_identifier) @keyword (#eq? @keyword "defer")) ; defer { ... }
147
148 (try_operator) @operator
149 (try_operator ["try" @keyword])
150
151 (directive) @function.macro
152 (diagnostic) @function.macro
153
154 ; Freestanding macro expansion (`#myMacro(…)`): colour the macro name. The `.`
155 ; anchors to the direct-child name so the call arguments are unaffected.
156 (macro_invocation . (simple_identifier) @function.macro)
157 ; Playground literals: `#colorLiteral(…)`, `#imageLiteral(…)`, `#fileLiteral(…)`.
158 (playground_literal
159 ["colorLiteral" "fileLiteral" "imageLiteral"] @function.macro)
160
161 ; Statements
162 (for_statement "for" @keyword.control.repeat)
163 (for_statement "in" @keyword.control.repeat)
164 ; The loop variable is now an `item: (pattern …)` (was a bare `simple_identifier`
165 ; pre-0.7). `for x in xs` is caught by the `pattern bound_identifier` rule above
166 ; and tuple bindings `for (k, v) in …` by the general `(simple_identifier)` rule,
167 ; so no dedicated rule is needed here.
168 (else) @keyword
169 (as_operator) @keyword
170
171 ["while" "repeat" "continue" "break"] @keyword.control.repeat
172
173 ["let" "var"] @keyword
174
175 (guard_statement "guard" @keyword.control.conditional)
176 (if_statement "if" @keyword.control.conditional)
177 (switch_statement "switch" @keyword.control.conditional)
178 (switch_entry "case" @keyword.control.conditional)
179 (switch_entry "fallthrough" @keyword.control.conditional)
180 (switch_entry (default_keyword) @keyword.control.conditional)
181 "return" @keyword.control.return
182 (ternary_expression
183 ["?" ":"] @keyword.control.conditional)
184
185 ["do" (throw_keyword) (catch_keyword)] @keyword.control.exception
186
187 (statement_label) @label
188
189 ; Comments
190 (comment) @comment
191 (multiline_comment) @comment
192
193 ; String literals
194 (line_str_text) @string
195 (str_escaped_char) @string
196 (multi_line_str_text) @string
197 (raw_str_part) @string
198 (raw_str_end_part) @string
199 (raw_str_interpolation_start) @punctuation.special
200 ["\"" "\"\"\""] @string
201
202 ; Lambda literals
203 (lambda_literal "in" @keyword.operator)
204
205 ; Basic literals
206 [
207 (hex_literal)
208 (oct_literal)
209 (bin_literal)
210 ] @constant.numeric
211 (integer_literal) @constant.numeric.integer
212 (real_literal) @constant.numeric.float
213 (boolean_literal) @constant.builtin.boolean
214 "nil" @constant.builtin
215
216 ; Magic compile-time literals: `#file`, `#fileID`, `#filePath`, `#line`,
217 ; `#column`, `#function`, `#dsohandle`. Colour the whole node (incl. the `#`).
218 (special_literal) @constant.builtin
219
220 (value_parameter_pack ["each" @keyword])
221 (value_pack_expansion ["repeat" @keyword])
222 (type_parameter_pack ["each" @keyword])
223 (type_pack_expansion ["repeat" @keyword])