Skip to content

Commit d0d2b03

Browse files
authored
Merge pull request #174 from rodrigues/elixir-queries
Update Elixir Highlights
2 parents 1076cf2 + c55277a commit d0d2b03

File tree

2 files changed

+207
-1
lines changed

2 files changed

+207
-1
lines changed

queries/elixir/highlights.scm

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
; Reserved keywords
2+
3+
; TODO: handle not in
4+
["when" "and" "or" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
5+
6+
; Interpolation
7+
8+
(interpolation
9+
"#{" @punctuation.special
10+
(_) @embedded
11+
"}" @punctuation.special)
12+
13+
; Operators
14+
15+
; * doc string
16+
(unary_operator
17+
operator: "@" @attribute
18+
operand: (call
19+
target: (identifier) @doc.__attribute__
20+
(arguments
21+
[
22+
(string) @doc
23+
(charlist) @doc
24+
(sigil
25+
quoted_start: _ @doc
26+
quoted_end: _ @doc) @doc
27+
(boolean) @doc
28+
]))
29+
(#match? @doc.__attribute__ "^(moduledoc|typedoc|doc)$"))
30+
31+
; * module attribute
32+
(unary_operator
33+
operator: "@" @attribute
34+
operand: [
35+
(identifier) @attribute
36+
(call
37+
target: (identifier) @attribute)
38+
(boolean) @attribute
39+
(nil) @attribute
40+
])
41+
42+
; * capture operand
43+
(unary_operator
44+
operator: "&"
45+
operand: (integer) @operator)
46+
47+
(operator_identifier) @operator
48+
49+
(unary_operator
50+
operator: _ @operator)
51+
52+
(binary_operator
53+
operator: _ @operator)
54+
55+
(dot
56+
operator: _ @operator)
57+
58+
(stab_clause
59+
operator: _ @operator)
60+
61+
; Literals
62+
63+
[
64+
(boolean)
65+
(nil)
66+
] @constant
67+
68+
[
69+
(integer)
70+
(float)
71+
] @number
72+
73+
(alias) @type
74+
75+
(call
76+
target: (dot
77+
left: (atom) @type))
78+
79+
(char) @constant
80+
81+
; Quoted content
82+
83+
(escape_sequence) @string.escape
84+
85+
[
86+
(atom)
87+
(quoted_atom)
88+
(keyword)
89+
(quoted_keyword)
90+
] @constant
91+
92+
[
93+
(string)
94+
(charlist)
95+
] @string
96+
97+
; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
98+
99+
(sigil
100+
(sigil_name) @__name__
101+
quoted_start: _ @string
102+
quoted_end: _ @string
103+
(#match? @__name__ "^[sS]$")) @string
104+
105+
(sigil
106+
(sigil_name) @__name__
107+
quoted_start: _ @string.regex
108+
quoted_end: _ @string.regex
109+
(#match? @__name__ "^[rR]$")) @string.regex
110+
111+
(sigil
112+
(sigil_name) @__name__
113+
quoted_start: _ @string.special
114+
quoted_end: _ @string.special) @string.special
115+
116+
; Calls
117+
118+
; * definition keyword
119+
(call
120+
target: (identifier) @keyword
121+
(#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
122+
123+
; * kernel or special forms keyword
124+
(call
125+
target: (identifier) @keyword
126+
(#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
127+
128+
; * just identifier in function definition
129+
(call
130+
target: (identifier) @keyword
131+
(arguments
132+
[
133+
(call target: (identifier) @function)
134+
(binary_operator
135+
left: (call
136+
target: (identifier) @function)
137+
operator: "when")
138+
])
139+
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
140+
141+
; * function call
142+
(call
143+
target: [
144+
; local
145+
(identifier) @function.call
146+
; remote
147+
(dot
148+
right: (identifier) @function.call)
149+
])
150+
151+
; * pipe into identifier (definition)
152+
(call
153+
target: (identifier) @keyword
154+
(arguments
155+
(binary_operator
156+
operator: "|>"
157+
right: (identifier) @variable))
158+
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
159+
160+
; * pipe into identifier (function call)
161+
(binary_operator
162+
operator: "|>"
163+
right: (identifier) @function.call)
164+
165+
; Identifiers
166+
167+
; * special
168+
(
169+
(identifier) @constant.builtin
170+
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
171+
)
172+
173+
; * unused
174+
(
175+
(identifier) @comment
176+
(#match? @comment "^_")
177+
)
178+
179+
; * regular
180+
(identifier) @variable
181+
182+
; Comment
183+
184+
(comment) @comment
185+
186+
; Punctuation
187+
188+
[
189+
"%"
190+
] @punctuation
191+
192+
[
193+
","
194+
";"
195+
] @punctuation.delimiter
196+
197+
[
198+
"("
199+
")"
200+
"["
201+
"]"
202+
"{"
203+
"}"
204+
"<<"
205+
">>"
206+
] @punctuation.bracket

0 commit comments

Comments
 (0)