@@ -1,125 +1,186 @@
1−["when" "and" "or" "not in" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
2−
3−[(true) (false) (nil)] @constant.builtin
4−
5−(keyword
6− [(keyword_literal)
7− ":"] @tag)
8−
9−(keyword
10− (keyword_string
11− [(string_start)
12− (string_content)
13− (string_end)] @tag))
14−
15−[(atom_literal)
16− (atom_start)
17− (atom_content)
18− (atom_end)] @tag
19−
20−[(comment)
21− (unused_identifier)] @comment
22−
23−(escape_sequence) @escape
24−
25−(call function: (function_identifier) @keyword
26− (#match? @keyword "^(defmodule|defexception|defp|def|with|case|cond|raise|import|require|use|defmacrop|defmacro|defguardp|defguard|defdelegate|defstruct|alias|defimpl|defprotocol|defoverridable|receive|if|for|try|throw|unless|reraise|super|quote|unquote|unquote_splicing)$"))
27−
28−(call function: (function_identifier) @keyword
29− [(call
30− function: (function_identifier) @function
31− (arguments
32− [(identifier) @variable.parameter
33− (_ (identifier) @variable.parameter)
34− (_ (_ (identifier) @variable.parameter))
35− (_ (_ (_ (identifier) @variable.parameter)))
36− (_ (_ (_ (_ (identifier) @variable.parameter))))
37− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
38− (binary_op
39− left:
40− (call
41− function: (function_identifier) @function
42− (arguments
43− [(identifier) @variable.parameter
44− (_ (identifier) @variable.parameter)
45− (_ (_ (identifier) @variable.parameter))
46− (_ (_ (_ (identifier) @variable.parameter)))
47− (_ (_ (_ (_ (identifier) @variable.parameter))))
48− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
1+; Reserved keywords
2+
3+["when" "and" "or" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
4+
5+; Operators
6+
7+; * doc string
8+(unary_operator
9+ operator: "@" @comment.doc
10+ operand: (call
11+ target: (identifier) @comment.doc.__attribute__
12+ (arguments
13+ [
14+ (string) @comment.doc
15+ (charlist) @comment.doc
16+ (sigil
17+ quoted_start: _ @comment.doc
18+ quoted_end: _ @comment.doc) @comment.doc
19+ (boolean) @comment.doc
20+ ]))
21+ (#match? @comment.doc.__attribute__ "^(moduledoc|typedoc|doc)$"))
22+
23+; * module attribute
24+(unary_operator
25+ operator: "@" @attribute
26+ operand: [
27+ (identifier) @attribute
28+ (call
29+ target: (identifier) @attribute)
30+ (boolean) @attribute
31+ (nil) @attribute
32+ ])
33+
34+; * capture operand
35+(unary_operator
36+ operator: "&"
37+ operand: (integer) @operator)
38+
39+(operator_identifier) @operator
40+
41+(unary_operator
42+ operator: _ @operator)
43+
44+(binary_operator
45+ operator: _ @operator)
46+
47+(dot
48+ operator: _ @operator)
49+
50+(stab_clause
51+ operator: _ @operator)
52+
53+; Literals
54+
55+[
56+ (boolean)
57+ (nil)
58+] @constant
59+
60+[
61+ (integer)
62+ (float)
63+] @number
64+
65+(alias) @type
66+
67+(char) @constant
68+
69+; Quoted content
70+
71+(interpolation "#{" @punctuation.special "}" @punctuation.special) @embedded
72+
73+(escape_sequence) @string.escape
74+
75+[
76+ (atom)
77+ (quoted_atom)
78+ (keyword)
79+ (quoted_keyword)
80+] @string.special.symbol
81+
82+[
83+ (string)
84+ (charlist)
85+] @string
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
92+ quoted_end: _ @string
93+ (#match? @__name__ "^[sS]$")) @string
94+
95+(sigil
96+ (sigil_name) @__name__
97+ quoted_start: _ @string.regex
98+ quoted_end: _ @string.regex
99+ (#match? @__name__ "^[rR]$")) @string.regex
100+
101+(sigil
102+ (sigil_name) @__name__
103+ quoted_start: _ @string.special
104+ quoted_end: _ @string.special) @string.special
105+
106+; Calls
107+
108+; * definition keyword
109+(call
110+ target: (identifier) @keyword
111+ (#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
112+
113+; * kernel or special forms keyword
114+(call
115+ target: (identifier) @keyword
116+ (#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
117+
118+; * function call
119+(call
120+ target: [
121+ ; local
122+ (identifier) @function
123+ ; remote
124+ (dot
125+ right: (identifier) @function)
126+ ])
127+
128+; * just identifier in function definition
129+(call
130+ target: (identifier) @keyword
131+ (arguments
132+ [
133+ (identifier) @function
134+ (binary_operator
135+ left: (identifier) @function
49136 operator: "when")
50− (binary_op
51− left: (identifier) @variable.parameter
52− operator: _ @function
53− right: (identifier) @variable.parameter)]
54− (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
55−
56−(call (function_identifier) @keyword
57− [(call
58− function: (function_identifier) @function)
59− (identifier) @function
60− (binary_op
61− left:
62− [(call
63− function: (function_identifier) @function)
64− (identifier) @function]
65− operator: "when")]
66− (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
67−
68−(anonymous_function
69− (stab_expression
70− left: (bare_arguments
71− [(identifier) @variable.parameter
72− (_ (identifier) @variable.parameter)
73− (_ (_ (identifier) @variable.parameter))
74− (_ (_ (_ (identifier) @variable.parameter)))
75− (_ (_ (_ (_ (identifier) @variable.parameter))))
76− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
77−
78−(unary_op
79− operator: "@"
80− (call (identifier) @attribute
81− (heredoc
82− [(heredoc_start)
83− (heredoc_content)
84− (heredoc_end)] @doc))
85− (#match? @attribute "^(doc|moduledoc)$"))
86−
87−(module) @type
88−
89−(unary_op
90− operator: "@" @attribute
91− [(call
92− function: (function_identifier) @attribute)
93− (identifier) @attribute])
94−
95−(unary_op
96− operator: _ @operator)
97−
98−(binary_op
99− operator: _ @operator)
100−
101−(heredoc
102− [(heredoc_start)
103− (heredoc_content)
104− (heredoc_end)] @string)
105−
106−(string
107− [(string_start)
108− (string_content)
109− (string_end)] @string)
110−
111−(sigil_start) @string.special
112−(sigil_content) @string
113−(sigil_end) @string.special
114−
115−(interpolation
116− "#{" @punctuation.special
117− "}" @punctuation.special)
137+ ])
138+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
139+
140+; * pipe into identifier (definition)
141+(call
142+ target: (identifier) @keyword
143+ (arguments
144+ (binary_operator
145+ operator: "|>"
146+ right: (identifier) @variable))
147+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
148+
149+; * pipe into identifier (function call)
150+(binary_operator
151+ operator: "|>"
152+ right: (identifier) @function)
153+
154+; Identifiers
155+
156+; * special
157+(
158+ (identifier) @constant.builtin
159+ (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
160+)
161+
162+; * unused
163+(
164+ (identifier) @comment.unused
165+ (#match? @comment.unused "^_")
166+)
167+
168+; * regular
169+(identifier) @variable
170+
171+; Comment
172+
173+(comment) @comment
174+
175+; Punctuation
176+
177+[
178+ "%"
179+] @punctuation
118180
119181[
120182 ","
121− "->"
122− "."
183+ ";"
123184] @punctuation.delimiter
124185
125186[
@@ -132,7 +193,3 @@
132193 "<<"
133194 ">>"
134195] @punctuation.bracket
135−
136−(special_identifier) @function.special
137−
138−(ERROR) @warning