1;; Copyright (c) Facebook, Inc. and its affiliates.
2;;
3;; Licensed under the Apache License, Version 2.0 (the "License");
4;; you may not use this file except in compliance with the License.
5;; You may obtain a copy of the License at
6;;
7;; http://www.apache.org/licenses/LICENSE-2.0
8;;
9;; Unless required by applicable law or agreed to in writing, software
10;; distributed under the License is distributed on an "AS IS" BASIS,
11;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12;; See the License for the specific language governing permissions and
13;; limitations under the License.
14;; ---------------------------------------------------------------------
15
16;; Based initially on the contents of https://github.com/WhatsApp/tree-sitter-erlang/issues/2 by @Wilfred
17;; and https://github.com/the-mikedavis/tree-sitter-erlang/blob/main/queries/highlights.scm
18;;
19;; The tests are also based on those in
20;; https://github.com/the-mikedavis/tree-sitter-erlang/tree/main/test/highlight
21;;
22
23;; Last match wins in this file.
24;; As of https://github.com/tree-sitter/tree-sitter/blob/master/CHANGELOG.md#breaking-1
25
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27;; Primitive types
28(string) @string
29(char) @constant
30(integer) @number
31(var) @variable
32(atom) @string.special.symbol
33
34;;; Comments
35((var) @comment.discard
36 (#match? @comment.discard "^_"))
37
38(dotdotdot) @comment.discard
39(comment) @comment
40
41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42;; Functions
43(fa fun: (atom) @function)
44(type_name name: (atom) @function)
45(call expr: (atom) @function)
46(function_clause name: (atom) @function)
47(internal_fun fun: (atom) @function)
48
49;; This is a fudge, we should check that the operator is '/'
50;; But our grammar does not (currently) provide it
51(binary_op_expr lhs: (atom) @function rhs: (integer))
52
53;; Others
54(remote_module module: (atom) @module)
55(remote fun: (atom) @function)
56(macro_call_expr name: (var) @constant)
57(macro_call_expr name: (var) @keyword.directive args: (_) )
58(macro_call_expr name: (atom) @keyword.directive)
59(record_field_name name: (atom) @property)
60(record_name name: (atom) @type)
61
62;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63;; Attributes
64
65;; module attribute
66(module_attribute
67 name: (atom) @module)
68
69;; behaviour
70(behaviour_attribute name: (atom) @module)
71
72;; export
73
74;; Import attribute
75(import_attribute
76 module: (atom) @module)
77
78;; export_type
79
80;; optional_callbacks
81
82;; compile
83(compile_options_attribute
84 options: (tuple
85 expr: (atom)
86 expr: (list
87 exprs: (binary_op_expr
88 lhs: (atom)
89 rhs: (integer)))))
90
91;; file attribute
92
93;; record
94(record_decl name: (atom) @type)
95(record_decl name: (macro_call_expr name: (var) @constant))
96(record_field name: (atom) @property)
97
98;; type alias
99
100;; opaque
101
102;; Spec attribute
103(spec fun: (atom) @function)
104(spec
105 module: (module name: (atom) @module)
106 fun: (atom) @function)
107
108;; callback
109(callback fun: (atom) @function)
110
111;; wild attribute
112(wild_attribute name: (attr_name name: (atom) @keyword))
113
114;; fun decl
115
116;; include/include_lib
117
118;; ifdef/ifndef
119(pp_ifdef name: (_) @keyword.directive)
120(pp_ifndef name: (_) @keyword.directive)
121
122;; define
123(pp_define
124 lhs: (macro_lhs
125 name: (var) @constant))
126(pp_define
127 lhs: (macro_lhs
128 name: (_) @keyword.directive
129 args: (var_args args: (var))))
130
131
132;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133;; Reserved words
134[ "after"
135 "and"
136 "band"
137 "begin"
138 "behavior"
139 "behaviour"
140 "bnot"
141 "bor"
142 "bsl"
143 "bsr"
144 "bxor"
145 "callback"
146 "case"
147 "catch"
148 "compile"
149 "define"
150 "deprecated"
151 "div"
152 "elif"
153 "else"
154 "end"
155 "endif"
156 "export"
157 "export_type"
158 "file"
159 "fun"
160 "if"
161 "ifdef"
162 "ifndef"
163 "import"
164 "include"
165 "include_lib"
166 "maybe"
167 "module"
168 "of"
169 "opaque"
170 "optional_callbacks"
171 "or"
172 "receive"
173 "record"
174 "spec"
175 "try"
176 "type"
177 "undef"
178 "unit"
179 "when"
180 "xor"] @keyword
181
182["andalso" "orelse"] @keyword.operator
183
184;; Punctuation
185["," "." ";"] @punctuation.delimiter
186["(" ")" "{" "}" "[" "]" "<<" ">>"] @punctuation.bracket
187
188;; Operators
189["!"
190 "->"
191 "<-"
192 "#"
193 "::"
194 "|"
195 ":"
196 "="
197 "||"
198
199 "+"
200 "-"
201 "bnot"
202 "not"
203
204 "/"
205 "*"
206 "div"
207 "rem"
208 "band"
209 "and"
210
211 "+"
212 "-"
213 "bor"
214 "bxor"
215 "bsl"
216 "bsr"
217 "or"
218 "xor"
219
220 "++"
221 "--"
222
223 "=="
224 "/="
225 "=<"
226 "<"
227 ">="
228 ">"
229 "=:="
230 "=/="
231 ] @operator