@@ -1,112 +1,142 @@
1+; ----------
2+; Primitives
3+; ----------
4+
5+[
6+ (line_comment)
7+ (block_comment)
8+] @comment
9+
10+(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|missing|Inf|NaN)$"))
11+(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true"))
12+(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false"))
13+
14+(integer_literal) @constant.numeric.integer
15+(float_literal) @constant.numeric.float
16+
17+(character_literal) @constant.character
18+(escape_sequence) @constant.character.escape
119
220(string_literal) @string
321
422(prefixed_string_literal
5− prefix: (identifier) @constant.builtin)
23+ prefix: (identifier) @function.macro) @string
624
7−(macro_identifier) @function.macro
8−(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight
9−(macro_definition
10− name: (identifier) @function.macro
11− ["macro" "end" @keyword])
25+(quote_expression
26+ (identifier) @string.special.symbol)
27+
28+; -------------------
29+; Modules and Imports
30+; -------------------
31+
32+(module_definition
33+ name: (identifier) @namespace)
34+
35+(import_statement
36+ (identifier) @namespace)
37+
38+(selected_import
39+ . (identifier) @namespace)
40+
41+(scoped_identifier
42+ (identifier) @namespace)
43+
44+; -----
45+; Types
46+; -----
47+
48+(abstract_definition
49+ name: (identifier) @type)
50+
51+(primitive_definition
52+ name: (identifier) @type)
1253
13−(field_expression
14− (identifier)
15− (identifier) @variable.other.member .)
54+(struct_definition
55+ name: (identifier) @type)
56+
57+(struct_definition
58+ . (_)
59+ (identifier) @variable.other.member)
60+
61+(struct_definition
62+ . (_)
63+ (typed_expression
64+ . (identifier) @variable.other.member))
65+
66+(type_parameter_list
67+ (identifier) @type)
68+
69+(constrained_parameter
70+ (identifier) @type)
71+
72+(subtype_clause
73+ (identifier) @type)
74+
75+(typed_expression
76+ (identifier) @type . )
77+
78+(parameterized_identifier
79+ (identifier) @type)
80+
81+(type_argument_list
82+ (identifier) @type)
83+
84+; -------------------
85+; Function definition
86+; -------------------
1687
1788(function_definition
1889 name: (identifier) @function)
19−(call_expression
20− (identifier) @function)
21−(call_expression
22− (field_expression (identifier) @function.method .))
23−(broadcast_call_expression
24− (identifier) @function)
25−(broadcast_call_expression
26− (field_expression (identifier) @function.method .))
90+
2791(parameter_list
2892 (identifier) @variable.parameter)
29−(parameter_list
30− (optional_parameter .
31− (identifier) @variable.parameter))
32−(typed_parameter
33− (identifier) @variable.parameter
34− (identifier) @type)
35−(type_parameter_list
36− (identifier) @type)
93+
3794(typed_parameter
3895 (identifier) @variable.parameter
39− (parameterized_identifier) @type)
40−(function_expression
96+ (identifier)? @type)
97+
98+(optional_parameter
4199 . (identifier) @variable.parameter)
42−(spread_parameter) @variable.parameter
100+
43101(spread_parameter
44102 (identifier) @variable.parameter)
45−(named_argument
46− . (identifier) @variable.parameter)
47−(argument_list
48− (typed_expression
49− (identifier) @variable.parameter
50− (identifier) @type))
51−(argument_list
52− (typed_expression
53− (identifier) @variable.parameter
54− (parameterized_identifier) @type))
55103
56−;; Symbol expressions (:my-wanna-be-lisp-keyword)
57−(quote_expression
58− (identifier)) @string.special.symbol
104+(function_expression
105+ . (identifier) @variable.parameter)
59106
60−;; Parsing error! foo (::Type) get's parsed as two quote expressions
61−(argument_list
62− (quote_expression
63− (quote_expression
64− (identifier) @type)))
107+; ---------------
108+; Functions calls
109+; ---------------
65110
66−(type_argument_list
67− (identifier) @type)
68−(parameterized_identifier (_)) @type
69−(argument_list
70− (typed_expression . (identifier) @variable.parameter))
111+(call_expression
112+ (identifier) @function)
71113
72−(typed_expression
73− (identifier) @type .)
74−(typed_expression
75− (parameterized_identifier) @type .)
114+(broadcast_call_expression
115+ (identifier) @function)
76116
77−(struct_definition
78− name: (identifier) @type)
117+(call_expression
118+ (field_expression (identifier) @function .))
79119
80−(integer_literal) @constant.numeric.integer
81−(float_literal) @constant.numeric.float
120+(broadcast_call_expression
121+ (field_expression (identifier) @function .))
122+
123+; ------
124+; Macros
125+; ------
126+
127+(macro_definition
128+ name: (identifier) @function.macro)
82129
83−(range_expression
84− (identifier) @constant.numeric.integer
85− (eq? @constant.numeric.integer "end"))
86−(range_expression
87− (_
88− (identifier) @constant.numeric.integer
89− (eq? @constant.numeric.integer "end")))
90−(coefficient_expression
91− [
92− (integer_literal)
93− (float_literal)
94− ]
95− (identifier) @constant.builtin)
96−
97−;; TODO: operators.
98−;; Those are a bit difficult to implement since the respective nodes are hidden right now (_power_operator)
99−;; and heavily use Unicode chars (support for those are bad in vim/lua regexes)
100−;[;
101− ;(power_operator);
102− ;(times_operator);
103− ;(plus_operator);
104− ;(arrow_operator);
105− ;(comparison_operator);
106− ;(assign_operator);
107−;] @operator ;
108−
109−"end" @keyword
130+(macro_identifier
131+ "@" @function.macro
132+ (identifier) @function.macro)
133+
134+; --------
135+; Keywords
136+; --------
137+
138+(function_definition
139+ ["function" "end"] @keyword.function)
110140
111141(if_statement
112142 ["if" "end"] @keyword.control.conditional)
@@ -117,36 +147,6 @@
117147(ternary_expression
118148 ["?" ":"] @keyword.control.conditional)
119149
120−(function_definition ["function" "end"] @keyword.function)
121−
122−[
123− (line_comment)
124− (block_comment)
125−] @comment
126−
127−[
128− "const"
129− "return"
130− "macro"
131− "struct"
132− "primitive"
133− "type"
134−] @keyword
135−
136−((identifier) @keyword (match? @keyword "global|local"))
137−
138−(compound_expression
139− ["begin" "end"] @keyword)
140−(try_statement
141− ["try" "end" ] @keyword.control.exception)
142−(finally_clause
143− "finally" @keyword.control.exception)
144−(catch_clause
145− "catch" @keyword.control.exception)
146−(quote_statement
147− ["quote" "end"] @keyword)
148−(let_statement
149− ["let" "end"] @keyword)
150150(for_statement
151151 ["for" "end"] @keyword.control.repeat)
152152(while_statement
@@ -157,33 +157,90 @@
157157 "in" @keyword.control.repeat)
158158(for_clause
159159 "for" @keyword.control.repeat)
160−(do_clause
161− ["do" "end"] @keyword)
162160
163−(export_statement
164− ["export"] @keyword.control.import)
161+(try_statement
162+ ["try" "end" ] @keyword.control.exception)
163+(finally_clause
164+ "finally" @keyword.control.exception)
165+(catch_clause
166+ "catch" @keyword.control.exception)
165167
166168[
167− "using"
168− "module"
169+ "export"
169170 "import"
171+ "using"
170172] @keyword.control.import
171173
172−((identifier) @keyword.control.import (#eq? @keyword.control.import "baremodule"))
174+[
175+ "abstract"
176+ "begin"
177+ "const"
178+ "do"
179+ "end"
180+ "let"
181+ "macro"
182+ "module"
183+ "mutable"
184+ "primitive"
185+ "quote"
186+ "return"
187+ "struct"
188+ "type"
189+] @keyword
190+
191+; TODO: fix this
192+((identifier) @keyword (match? @keyword "global|local"))
173193
174−(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|Inf|NaN)$"))
175−(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true"))
176−(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false"))
194+; ---------
195+; Operators
196+; ---------
197+
198+[
199+ (operator)
200+ "::"
201+ "<:"
202+ ":"
203+ "=>"
204+ "..."
205+ "$"
206+] @operator
207+
208+; ------------
209+; Punctuations
210+; ------------
211+
212+[
213+ "."
214+ ","
215+ ";"
216+] @punctuation.delimiter
217+
218+[
219+ "["
220+ "]"
221+ "("
222+ ")"
223+ "{"
224+ "}"
225+] @punctuation.bracket
226+
227+; ---------------------
228+; Remaining identifiers
229+; ---------------------
230+
231+; could also be namespace but this should cover the majority
232+(field_expression
233+ . (_)
234+ (identifier) @variable.other.member)
177235
236+(const_statement
237+ (variable_declaration
238+ . (identifier) @constant))
178239
179−["::" ":" "." "," "..."] @punctuation.delimiter
180−["[" "]" "(" ")" "{" "}"] @punctuation.bracket
240+((identifier) @type
241+ (match? @type "([A-Z][a-z0-9]+)+$"))
181242
182−["="] @operator
243+((identifier) @constant
244+ (match? @constant "^[A-Z][A-Z0-9_]+$"))
183245
184246(identifier) @variable
185−;; In case you want type highlighting based on Julia naming conventions (this might collide with mathematical notation)
186−;((identifier) @type ; exception: mark `A_foo` sort of identifiers as variables
187− ;(match? @type "^[A-Z][^_]"))
188−((identifier) @constant
189− (match? @constant "^[A-Z][A-Z_]{2}[A-Z_]*$"))