on master help sign in
Julia queries: major refactoring of `highlights.scm`, add regex injections, locals
f5c00b9Christoph Horn
runtime/queries/julia/highlights.scm+191−134
@@ -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
1
19
2(string_literal) @string
20(string_literal) @string
3
21
4(prefixed_string_literal
22(prefixed_string_literal
5− prefix: (identifier) @constant.builtin)
23+ prefix: (identifier) @function.macro) @string
6
24
7−(macro_identifier) @function.macro
25+(quote_expression
8−(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight
26+ (identifier) @string.special.symbol)
9−(macro_definition
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
10− name: (identifier) @function.macro
49+ name: (identifier) @type)
11− ["macro" "end" @keyword])
50+
51+(primitive_definition
52+ name: (identifier) @type)
12
53
13−(field_expression
54+(struct_definition
14− (identifier)
55+ name: (identifier) @type)
56+
57+(struct_definition
58+ . (_)
59+ (identifier) @variable.other.member)
60+
61+(struct_definition
62+ . (_)
63+ (typed_expression
15− (identifier) @variable.other.member .)
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+; -------------------
16
87
17(function_definition
88(function_definition
18 name: (identifier) @function)
89 name: (identifier) @function)
19−(call_expression
90+
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 .))
27(parameter_list
91(parameter_list
28 (identifier) @variable.parameter)
92 (identifier) @variable.parameter)
29−(parameter_list
93+
30− (optional_parameter .
31− (identifier) @variable.parameter))
32−(typed_parameter
33− (identifier) @variable.parameter
34− (identifier) @type)
35−(type_parameter_list
36− (identifier) @type)
37(typed_parameter
94(typed_parameter
38 (identifier) @variable.parameter
95 (identifier) @variable.parameter
39− (parameterized_identifier) @type)
96+ (identifier)? @type)
40−(function_expression
97+
98+(optional_parameter
41 . (identifier) @variable.parameter)
99 . (identifier) @variable.parameter)
42−(spread_parameter) @variable.parameter
100+
43(spread_parameter
101(spread_parameter
44 (identifier) @variable.parameter)
102 (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))
55
103
56−;; Symbol expressions (:my-wanna-be-lisp-keyword)
104+(function_expression
57−(quote_expression
105+ . (identifier) @variable.parameter)
58− (identifier)) @string.special.symbol
59
106
60−;; Parsing error! foo (::Type) get's parsed as two quote expressions
107+; ---------------
61−(argument_list
108+; Functions calls
62− (quote_expression
109+; ---------------
63− (quote_expression
64− (identifier) @type)))
65
110
66−(type_argument_list
111+(call_expression
67− (identifier) @type)
112+ (identifier) @function)
68−(parameterized_identifier (_)) @type
69−(argument_list
70− (typed_expression . (identifier) @variable.parameter))
71
113
72−(typed_expression
114+(broadcast_call_expression
73− (identifier) @type .)
115+ (identifier) @function)
74−(typed_expression
75− (parameterized_identifier) @type .)
76
116
77−(struct_definition
117+(call_expression
78− name: (identifier) @type)
118+ (field_expression (identifier) @function .))
79
119
80−(integer_literal) @constant.numeric.integer
120+(broadcast_call_expression
81−(float_literal) @constant.numeric.float
121+ (field_expression (identifier) @function .))
122+
123+; ------
124+; Macros
125+; ------
126+
127+(macro_definition
128+ name: (identifier) @function.macro)
82
129
83−(range_expression
130+(macro_identifier
84− (identifier) @constant.numeric.integer
131+ "@" @function.macro
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)
132+ (identifier) @function.macro)
96−
133+
97−;; TODO: operators.
134+; --------
98−;; Those are a bit difficult to implement since the respective nodes are hidden right now (_power_operator)
135+; Keywords
99−;; and heavily use Unicode chars (support for those are bad in vim/lua regexes)
136+; --------
100−;[;
137+
101− ;(power_operator);
138+(function_definition
102− ;(times_operator);
103− ;(plus_operator);
104− ;(arrow_operator);
105− ;(comparison_operator);
106− ;(assign_operator);
107−;] @operator ;
108−
109−"end" @keyword
139+ ["function" "end"] @keyword.function)
110
140
111(if_statement
141(if_statement
112 ["if" "end"] @keyword.control.conditional)
142 ["if" "end"] @keyword.control.conditional)
@@ -117,36 +147,6 @@
117(ternary_expression
147(ternary_expression
118 ["?" ":"] @keyword.control.conditional)
148 ["?" ":"] @keyword.control.conditional)
119
149
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)
150(for_statement
150(for_statement
151 ["for" "end"] @keyword.control.repeat)
151 ["for" "end"] @keyword.control.repeat)
152(while_statement
152(while_statement
@@ -157,33 +157,90 @@
157 "in" @keyword.control.repeat)
157 "in" @keyword.control.repeat)
158(for_clause
158(for_clause
159 "for" @keyword.control.repeat)
159 "for" @keyword.control.repeat)
160−(do_clause
161− ["do" "end"] @keyword)
162
160
163−(export_statement
161+(try_statement
164− ["export"] @keyword.control.import)
162+ ["try" "end" ] @keyword.control.exception)
163+(finally_clause
164+ "finally" @keyword.control.exception)
165+(catch_clause
166+ "catch" @keyword.control.exception)
165
167
166[
168[
167− "using"
169+ "export"
168− "module"
169 "import"
170 "import"
171+ "using"
170] @keyword.control.import
172] @keyword.control.import
171
173
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
172−((identifier) @keyword.control.import (#eq? @keyword.control.import "baremodule"))
192+((identifier) @keyword (match? @keyword "global|local"))
173
193
174−(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|Inf|NaN)$"))
194+; ---------
175−(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true"))
195+; Operators
176−(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false"))
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)
177
235
236+(const_statement
237+ (variable_declaration
238+ . (identifier) @constant))
178
239
179−["::" ":" "." "," "..."] @punctuation.delimiter
240+((identifier) @type
180−["[" "]" "(" ")" "{" "}"] @punctuation.bracket
241+ (match? @type "([A-Z][a-z0-9]+)+$"))
181
242
182−["="] @operator
243+((identifier) @constant
244+ (match? @constant "^[A-Z][A-Z0-9_]+$"))
183
245
184(identifier) @variable
246(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_]*$"))
runtime/queries/julia/injections.scm+14−6
@@ -1,8 +1,16 @@
1+(
1−; ((string_literal) @injection.content
2+ (string_literal) @injection.content
2−; (#set! injection.language "markdown"))
3+ (#set! injection.language "markdown"))
3
4
5+(
6+ [
7+ (line_comment)
8+ (block_comment)
4−; ((line_comment) @injection.content
9+ ] @injection.content
5−; (#set! injection.language "comment"))
10+ (#set! injection.language "comment"))
6
11
12+(
13+ (prefixed_string_literal
7−; ((block_comment) @injection.content
14+ prefix: (identifier) @function.macro) @injection.content
15+ (#eq? @function.macro "re")
8−; (#set! injection.language "comment"))
16+ (#set! injection.language "regex"))
runtime/queries/julia/locals.scm+33−49
@@ -1,59 +1,43 @@
1+; -----------
2+; Definitions
3+; -----------
1
4
5+; Imports
2(import_statement
6(import_statement
3− (identifier) @definition.import)
4−(variable_declaration
5− (identifier) @local.definition)
7+ (identifier) @local.definition)
6−(variable_declaration
8+
7− (tuple_expression
9+; Constants
8− (identifier) @local.definition))
10+(const_statement
9−(for_binding
11+ (variable_declaration
10− (identifier) @local.definition)
11−(for_binding
12− (tuple_expression
13− (identifier) @local.definition))
14−
15−(assignment_expression
16− (tuple_expression
17− (identifier) @local.definition))
18−(assignment_expression
19− (bare_tuple_expression
20− (identifier) @local.definition))
21−(assignment_expression
22− (identifier) @local.definition)
12+ . (identifier) @local.definition))
23−
24−(type_parameter_list
25− (identifier) @definition.type)
26−(type_argument_list
27− (identifier) @definition.type)
28−(struct_definition
29− name: (identifier) @definition.type)
30
13
14+; Parameters
31(parameter_list
15(parameter_list
32− (identifier) @definition.parameter)
16+ (identifier) @local.definition)
17+
33(typed_parameter
18(typed_parameter
34− (identifier) @definition.parameter
19+ . (identifier) @local.definition)
35− (identifier))
36−(function_expression
37− . (identifier) @definition.parameter)
38−(argument_list
39− (typed_expression
40− (identifier) @definition.parameter
41− (identifier)))
42−(spread_parameter
43− (identifier) @definition.parameter)
44
20
45−(function_definition
21+(optional_parameter .
46− name: (identifier) @definition.function) @local.scope
47−(macro_definition
48− name: (identifier) @definition.macro) @local.scope
22+ (identifier) @local.definition)
49
23
24+(spread_parameter
25+ (identifier) @local.definition)
26+
27+(function_expression
50−(identifier) @local.reference
28+ . (identifier) @local.definition)
29+
30+; ------
31+; Scopes
32+; ------
51
33
52[
34[
53− (try_statement)
35+ (function_definition)
54− (finally_clause)
36+ (macro_definition)
55− (quote_statement)
56− (let_statement)
57− (compound_expression)
58− (for_statement)
59] @local.scope
37] @local.scope
38+
39+; ----------
40+; References
41+; ----------
42+
43+(identifier) @local.reference