Debian Codegraph @

runtime/queries/elixir/highlights.scm

raw symbols SCIP
1 ; The following code originates mostly from
2 ; https://github.com/elixir-lang/tree-sitter-elixir, with minor edits to
3 ; align the captures with helix. The following should be considered
4 ; Copyright 2021 The Elixir Team
5 ;
6 ; Licensed under the Apache License, Version 2.0 (the "License");
7 ; you may not use this file except in compliance with the License.
8 ; You may obtain a copy of the License at
9 ;
10 ; https://www.apache.org/licenses/LICENSE-2.0
11 ;
12 ; Unless required by applicable law or agreed to in writing, software
13 ; distributed under the License is distributed on an "AS IS" BASIS,
14 ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ; See the License for the specific language governing permissions and
16 ; limitations under the License.
17
18 ; Punctuation
19
20 [
21 "%"
22 ] @punctuation
23
24 [
25 ","
26 ";"
27 ] @punctuation.delimiter
28
29 [
30 "("
31 ")"
32 "["
33 "]"
34 "{"
35 "}"
36 "<<"
37 ">>"
38 ] @punctuation.bracket
39
40 ; Literals
41
42 (boolean) @constant.builtin.boolean
43 (nil) @constant.builtin
44 (integer) @constant.numeric.integer
45 (float) @constant.numeric.float
46 (char) @constant.character
47
48 ; Identifiers
49
50 ; * regular
51 (identifier) @variable
52
53 ; * unused
54 (
55 (identifier) @comment.unused
56 (#match? @comment.unused "^_")
57 )
58
59 ; * special
60 (
61 (identifier) @constant.builtin
62 (#any-of? @constant.builtin "__MODULE__" "__DIR__" "__ENV__" "__CALLER__" "__STACKTRACE__")
63 )
64
65 ; Comment
66
67 (comment) @comment
68
69 ; Quoted content
70
71 (interpolation "#{" @punctuation.special "}" @punctuation.special) @embedded
72
73 (escape_sequence) @constant.character.escape
74
75 [
76 (string)
77 (charlist)
78 ] @string
79
80 [
81 (atom)
82 (quoted_atom)
83 (keyword)
84 (quoted_keyword)
85 ] @string.special.symbol
86
87 ; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
88
89 (sigil
90 (sigil_name) @__name__
91 quoted_start: _ @string.special
92 quoted_end: _ @string.special) @string.special
93
94 (sigil
95 (sigil_name) @__name__
96 quoted_start: _ @string
97 quoted_end: _ @string
98 (#match? @__name__ "^[sS]$")) @string
99
100 (sigil
101 (sigil_name) @__name__
102 quoted_start: _ @string.regexp
103 quoted_end: _ @string.regexp
104 (#match? @__name__ "^[rR]$")) @string.regexp
105
106 ; Calls
107
108 ; * local function call
109 (call
110 target: (identifier) @function)
111
112 ; * remote function call
113 (call
114 target: (dot
115 right: (identifier) @function))
116
117 ; * field without parentheses or block
118 (call
119 target: (dot
120 right: (identifier) @variable.other.member)
121 .)
122
123 ; * remote call without parentheses or block (overrides above)
124 (call
125 target: (dot
126 left: [
127 (alias)
128 (atom)
129 ]
130 right: (identifier) @function)
131 .)
132
133 ; * definition keyword
134 (call
135 target: (identifier) @keyword
136 (#any-of? @keyword "def" "defdelegate" "defexception" "defguard" "defguardp" "defimpl" "defmacro" "defmacrop" "defmodule" "defn" "defnp" "defoverridable" "defp" "defprotocol" "defstruct"))
137
138 ; * kernel or special forms keyword
139 (call
140 target: (identifier) @keyword
141 (#any-of? @keyword "alias" "case" "cond" "for" "if" "import" "quote" "raise" "receive" "require" "reraise" "super" "throw" "try" "unless" "unquote" "unquote_splicing" "use" "with"))
142
143 ; * just identifier in function definition
144 (call
145 target: (identifier) @keyword
146 (arguments
147 [
148 (identifier) @function
149 (binary_operator
150 left: (identifier) @function
151 operator: "when")
152 ])
153 (#any-of? @keyword "def" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp" "defp"))
154
155 ; * pipe into identifier (function call)
156 (binary_operator
157 operator: "|>"
158 right: (identifier) @function)
159
160 ; * pipe into identifier (definition)
161 (call
162 target: (identifier) @keyword
163 (arguments
164 (binary_operator
165 operator: "|>"
166 right: (identifier) @variable))
167 (#any-of? @keyword "def" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp" "defp"))
168
169 ; * pipe into field without parentheses (function call)
170 (binary_operator
171 operator: "|>"
172 right: (call
173 target: (dot
174 right: (identifier) @function)))
175
176 ; Operators
177
178 ; * capture operand
179 (unary_operator
180 operator: "&"
181 operand: [
182 (integer) @operator
183 (binary_operator
184 left: [
185 (call target: (dot left: (_) right: (identifier) @function))
186 (identifier) @function
187 ] operator: "/" right: (integer) @operator)
188 ])
189
190 (operator_identifier) @operator
191
192 (unary_operator
193 operator: _ @operator)
194
195 (binary_operator
196 operator: _ @operator)
197
198 (dot
199 operator: _ @operator)
200
201 (stab_clause
202 operator: _ @operator)
203
204 ; * module attribute
205 (unary_operator
206 operator: "@" @variable.other.member
207 operand: [
208 (identifier) @variable.other.member
209 (call
210 target: (identifier) @variable.other.member)
211 (boolean) @variable.other.member
212 (nil) @variable.other.member
213 ])
214
215 ; * doc string
216 (unary_operator
217 operator: "@" @comment.block.documentation
218 operand: (call
219 target: (identifier) @comment.block.documentation.__attribute__
220 (arguments
221 [
222 (string) @comment.block.documentation
223 (charlist) @comment.block.documentation
224 (sigil
225 quoted_start: _ @comment.block.documentation
226 quoted_end: _ @comment.block.documentation) @comment.block.documentation
227 (boolean) @comment.block.documentation
228 ]))
229 (#any-of? @comment.block.documentation.__attribute__ "moduledoc" "typedoc" "doc"))
230
231 ; Module
232
233 (alias) @namespace
234
235 (call
236 target: (dot
237 left: (atom) @namespace))
238
239 ; Reserved keywords
240
241 ["when" "and" "or" "not" "in" "not in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword