@@ -1,125 +1,213 @@
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
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
10+; https://www.apache.org/licenses/LICENSE-2.0
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.
1−["when" "and" "or" "not in" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
20+["when" "and" "or" "not" "in" "not in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
26+ operator: "@" @comment.block.documentation
28+ target: (identifier) @comment.block.documentation.__attribute__
31+ (string) @comment.block.documentation
32+ (charlist) @comment.block.documentation
34+ quoted_start: _ @comment.block.documentation
35+ quoted_end: _ @comment.block.documentation) @comment.block.documentation
36+ (boolean) @comment.block.documentation
38+ (#match? @comment.block.documentation.__attribute__ "^(moduledoc|typedoc|doc)$"))
42+ operator: "@" @variable.property
44+ (identifier) @variable.property
46+ target: (identifier) @variable.property)
47+ (boolean) @variable.property
48+ (nil) @variable.property
58+ (call target: (dot left: (_) right: (identifier) @function))
59+ (identifier) @function
60+ ] operator: "/" right: (integer) @operator)
63+(operator_identifier) @operator
66+ operator: _ @operator)
69+ operator: _ @operator)
72+ operator: _ @operator)
75+ operator: _ @operator)
79+(nil) @constant.builtin
81+(boolean) @constant.builtin.boolean
3−[(true) (false) (nil)] @constant.builtin
83+[
6− [(keyword_literal)
91+ target: (dot
7− ":"] @tag)
92+ left: (atom) @type))
9−(keyword
94+(char) @constant.character
15−[(atom_literal)
96+; Quoted content
20−[(comment)
98+(interpolation "#{" @escape "}" @escape) @embedded
21− (unused_identifier)] @comment
23(escape_sequence) @escape
100(escape_sequence) @escape
25−(call function: (function_identifier) @keyword
102+[
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)$"))
103+ (atom)
28−(call function: (function_identifier) @keyword
105+ (keyword)
107+] @string.special.symbol
114+; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
117+ (sigil_name) @__name__
118+ quoted_start: _ @string
119+ quoted_end: _ @string
120+ (#match? @__name__ "^[sS]$")) @string
123+ (sigil_name) @__name__
124+ quoted_start: _ @string.regex
125+ quoted_end: _ @string.regex
126+ (#match? @__name__ "^[rR]$")) @string.regex
129+ (sigil_name) @__name__
130+ quoted_start: _ @string.special
131+ quoted_end: _ @string.special) @string.special
135+; * definition keyword
137+ target: (identifier) @keyword
138+ (#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
140+; * kernel or special forms keyword
142+ target: (identifier) @keyword
143+ (#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
30− function: (function_identifier) @function
147+ target: [
31− (arguments
148+ ; local
32− [(identifier) @variable.parameter
33− (_ (identifier) @variable.parameter)
149+ (identifier) @function
34− (_ (_ (identifier) @variable.parameter))
150+ ; remote
35− (_ (_ (_ (identifier) @variable.parameter)))
151+ (dot
36− (_ (_ (_ (_ (identifier) @variable.parameter))))
152+ right: (identifier) @function)
155+; * just identifier in function definition
157+ target: (identifier) @keyword
37− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
160+ (identifier) @function
38− (binary_op
161+ (binary_operator
41− function: (function_identifier) @function
43− [(identifier) @variable.parameter
162+ left: (identifier) @function
44− (_ (identifier) @variable.parameter)
45− (_ (_ (identifier) @variable.parameter))
46− (_ (_ (_ (identifier) @variable.parameter)))
47− (_ (_ (_ (_ (identifier) @variable.parameter))))
48− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
49 operator: "when")
163 operator: "when")
51− left: (identifier) @variable.parameter
165+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
52− operator: _ @function
166+
53− right: (identifier) @variable.parameter)]
167+; * pipe into identifier (definition)
54− (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
56−(call (function_identifier) @keyword
58− function: (function_identifier) @function)
59− (identifier) @function
169+ target: (identifier) @keyword
60− (binary_op
170+ (arguments
61− left:
171+ (binary_operator
62− [(call
172+ operator: "|>"
63− function: (function_identifier) @function)
64− (identifier) @function]
173+ right: (identifier) @variable))
65− operator: "when")]
174+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
66− (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
175+
67−
176+; * pipe into identifier (function call)
68−(anonymous_function
177+(binary_operator
69− (stab_expression
178+ operator: "|>"
70− left: (bare_arguments
179+ right: (identifier) @function)
71− [(identifier) @variable.parameter
180+
72− (_ (identifier) @variable.parameter)
181+; Identifiers
73− (_ (_ (identifier) @variable.parameter))
182+
74− (_ (_ (_ (identifier) @variable.parameter)))
183+; * special
75− (_ (_ (_ (_ (identifier) @variable.parameter))))
184+(
76− (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
185+ (identifier) @constant.builtin
77−
186+ (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
80− (call (identifier) @attribute
189+; * unused
82− [(heredoc_start)
191+ (identifier) @comment
83− (heredoc_content)
192+ (#match? @comment "^_")
84− (heredoc_end)] @doc))
193+)
85− (#match? @attribute "^(doc|moduledoc)$"))
194+
87−(module) @type
196+(identifier) @variable
89−(unary_op
198+; Comment
90− operator: "@" @attribute
199+
91− [(call
200+(comment) @comment
92− function: (function_identifier) @attribute)
201+
93− (identifier) @attribute])
202+; Punctuation
96− operator: _ @operator)
205+ "%"
99− operator: _ @operator)
104− (heredoc_end)] @string)
109− (string_end)] @string)
111−(sigil_start) @string.special
112−(sigil_content) @string
113−(sigil_end) @string.special
116− "#{" @punctuation.special
117− "}" @punctuation.special)
206+] @punctuation
123] @punctuation.delimiter
211] @punctuation.delimiter
@@ -133,6 +221,4 @@
134] @punctuation.bracket
222] @punctuation.bracket
136−(special_identifier) @function.special
138(ERROR) @warning
224(ERROR) @warning