summaryrefslogtreecommitdiff
path: root/queries/elixir/highlights.scm
blob: bcbc43918752733a5a548abcaecf134ee68418f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
(identifier) @variable

; _unused variables
(unused_identifier) @comment

; __MODULE__ and friends
(special_identifier) @constant.builtin

(module) @type

[(atom) (keyword)] @symbol

(integer) @number
(float) @float

[(true) (false)] @boolean

(nil) @constant.builtin

(comment) @comment

[
  ","
  "."
] @punctuation.delimiter

[
  "("
  ")"
  "["
  "]"
  "{"
  "}"
  "<<"
  ">>"
] @punctuation.bracket

(interpolation
 "#{" @punctuation.special
 "}" @punctuation.special) @none

[
  (heredoc_content)
  (sigil_content)
  (string_content)
  (string_end)
  (string_start)
] @string

[
  (heredoc_end)
  (heredoc_start)
  (sigil_end)
  (sigil_start)
] @string.special

(escape_sequence) @string.escape

[
  "after"
  "do"
  "end"
] @keyword

[
  "and"
  "in"
  "not"
  "not in"
  "or"
] @keyword.operator

; Call to a local function
(call (function_identifier) @method)

; Call to a remote (or external) function
(dot_call
 remote: [(atom) (module)] @type
 function: (function_identifier) @method)

"fn" @keyword.function

; def, defp, defguard, ... everything that starts with def
(call (function_identifier) @keyword.function
 (#lua-match? @keyword.function "^def%a*$"))

(call (function_identifier) @keyword.function
 (#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))

"else" @conditional

(call (function_identifier) @conditional
 (#any-of? @conditional "case" "cond" "if" "unless" "with"))

(call (function_identifier) @repeat
 (#eq? @repeat "for"))

(call (function_identifier) @include
 (#any-of? @include "alias" "import" "require" "use"))

[
  "catch"
  "rescue"
] @exception

(call (function_identifier) @exception
 (#any-of? @exception "raise" "try"))

; Regex sigil
(sigil
 (sigil_start) @_sigil-type
 [(sigil_content) (escape_sequence)] @string.regex
 (sigil_end)
 (#lua-match? @_sigil-type "^~r"))

"->" @operator

(unary_op
 operator: _ @operator)

(binary_op
 operator: _ @operator)

(unary_op
 operator: "@" @attribute
 [(call
   function: (function_identifier) @attribute)
  (identifier) @attribute])

(unary_op
 operator: "@"
 (call (function_identifier) @attribute
       (heredoc
        [(heredoc_start)
         (heredoc_content)
         (heredoc_end)] @string))
 (#any-of? @attribute "doc" "moduledoc"))

(unary_op
 operator: "@"
 (call (function_identifier) @attribute
       (binary_op
        left: (identifier) @method))
 (#eq? @attribute "spec"))

; Definition without arguments
(call (function_identifier) @keyword.function
 (identifier) @function 
 (#lua-match? @keyword.function "^def%a*$"))

; Definition with (some) arguments and (optional) defaults
(call (function_identifier) @keyword.function
 (call
  function: (function_identifier) @function
    (arguments))
 (#lua-match? @keyword.function "^def%a*$"))

; Definition with (some) arguments and guard(s)
(call (function_identifier) @keyword.function
 (binary_op
  left:
   (call
    function: (function_identifier) @function
    (arguments))
  operator: "when")
 (#lua-match? @keyword.function "^def%a*$"))

; Definition of custom binary operator(s)
(call (function_identifier) @keyword.function
 (binary_op
  left: (identifier) @parameter
  operator: _ @function
  right: (identifier) @parameter)
 (#any-of? @keyword.function "def" "defp"))

(ERROR) @error