@@ -144,23 +144,38 @@ Otherwise, the indentation is:
144
144
(treesit-font-lock-rules
145
145
:language 'julia
146
146
:feature 'assignment
147
- `((assignment :anchor [(identifier) (operator)] @font-lock- variable-name-face)
147
+ `(; ; regular variable assignments
148
148
(assignment
149
149
:anchor
150
- (field_expression
151
- value: (identifier) " ." (identifier) @font-lock-variable-name-face))
152
- (assignment (open_tuple (identifier) @font-lock-variable-name-face))
150
+ [(identifier) (operator)] @font-lock-variable-name-face)
151
+ (assignment
152
+ :anchor
153
+ (field_expression " ." (identifier) @font-lock-variable-name-face))
154
+ ; ; open tuple assignments (comma separated variables without parentheses)
155
+ (assignment
156
+ :anchor
157
+ (open_tuple (identifier) @font-lock-variable-name-face))
153
158
(assignment
154
159
:anchor
155
160
(open_tuple
156
- (field_expression
157
- value: (identifier) " ." (identifier) @font-lock-variable-name-face)))
158
- (local_statement (identifier) @font-lock-variable-name-face)
161
+ (field_expression " ." (identifier) @font-lock-variable-name-face)))
162
+ ; ; closed tuple assignments (comma separated variables with parentheses)
163
+ (assignment
164
+ :anchor
165
+ (tuple_expression (identifier) @font-lock-variable-name-face))
166
+ (assignment
167
+ :anchor
168
+ (tuple_expression
169
+ (field_expression " ." (identifier) @font-lock-variable-name-face)))
170
+ ; ; let blocks
159
171
(let_statement :anchor (identifier) @font-lock-variable-name-face)
160
172
((let_statement _ @comma :anchor (identifier) @font-lock-variable-name-face)
161
173
(:equal " ," @comma))
162
174
(let_binding :anchor (identifier) @font-lock-variable-name-face)
175
+ ; ; local and global statements
176
+ (local_statement (identifier) @font-lock-variable-name-face)
163
177
(global_statement (identifier) @font-lock-variable-name-face)
178
+ ; ; named (keyword) argument names with assigned values
164
179
(named_argument (identifier) @julia-ts-keyword-argument-face (operator)))
165
180
166
181
:language 'julia
@@ -177,81 +192,27 @@ Otherwise, the indentation is:
177
192
178
193
:language 'julia
179
194
:feature 'definition
180
- `((function_definition
181
- (signature (identifier) @font-lock-function-name-face))
182
- (function_definition
183
- (signature
184
- (call_expression [(identifier) (operator)] @font-lock-function-name-face)))
185
- (function_definition
186
- (signature
187
- (typed_expression
188
- (call_expression [(identifier) (operator)] @font-lock-function-name-face))))
189
- (function_definition
190
- (signature
191
- (where_expression
192
- (call_expression [(identifier) (operator)] @font-lock-function-name-face))))
193
- (function_definition
194
- (signature
195
- (where_expression
196
- (typed_expression
197
- (call_expression [(identifier) (operator)] @font-lock-function-name-face)))))
198
- (function_definition
199
- (signature
200
- (call_expression
201
- (field_expression
202
- value: (identifier) " ." (identifier) @font-lock-function-name-face))))
195
+ `(; ; function declaration
203
196
(function_definition
204
- (signature
205
- (typed_expression
206
- (call_expression
207
- (field_expression
208
- value: (identifier) " ." (identifier) @font-lock-function-name-face)))))
209
- (macro_definition
210
- (signature
211
- (call_expression (identifier) @font-lock-function-name-face)))
212
- (macro_definition
213
- (signature
214
- (call_expression
215
- (field_expression
216
- value: (identifier) " ." (identifier) @font-lock-function-name-face))))
217
- (abstract_definition
218
- (type_head (identifier) @font-lock-type-face))
219
- (abstract_definition
220
- (type_head (binary_expression (identifier) @font-lock-type-face)))
221
- (primitive_definition
222
- (type_head (identifier) @font-lock-type-face))
223
- (primitive_definition
224
- (type_head (binary_expression (identifier) @font-lock-type-face)))
225
- (struct_definition
226
- (type_head (identifier) @font-lock-type-face))
227
- (struct_definition
228
- (type_head (binary_expression (identifier) @font-lock-type-face)))
229
- (assignment
230
- :anchor
231
- (call_expression [(identifier) (operator)] @font-lock-function-name-face))
232
- (assignment
233
- :anchor
234
- (call_expression
235
- (parenthesized_expression
236
- [(identifier) (operator)] @font-lock-function-name-face)))
237
- (assignment
238
- :anchor
239
- (call_expression
240
- (field_expression
241
- value: (identifier) " ." (identifier) @font-lock-function-name-face)))
242
- (assignment
243
- :anchor
244
- (where_expression
245
- (call_expression (identifier) @font-lock-function-name-face)))
246
- (assignment
247
- :anchor
248
- (where_expression
249
- (call_expression
250
- (field_expression
251
- value: (identifier) " ." (identifier) @font-lock-function-name-face))))
197
+ (signature (identifier) @font-lock-function-name-face))
198
+ ; ; function definitions (long and short syntax)
199
+ (call_expression
200
+ [(identifier) (operator)] @font-lock-function-name-face
201
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
202
+ (call_expression
203
+ (parenthesized_expression
204
+ [(identifier) (operator)] @font-lock-function-name-face)
205
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
206
+ (call_expression
207
+ (field_expression " ." [(identifier) (operator)] @font-lock-function-name-face)
208
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
209
+ ; ; binary operator definition as assignment
252
210
(assignment
253
211
:anchor
254
- (binary_expression _ (operator) @font-lock-function-name-face)))
212
+ (binary_expression _ (operator) @font-lock-function-name-face))
213
+ ; ; struct/abstract type/primitive type definitions
214
+ (type_head (identifier) @font-lock-type-face)
215
+ (type_head (binary_expression (identifier) @font-lock-type-face)))
255
216
256
217
:language 'julia
257
218
:feature 'error
@@ -315,6 +276,12 @@ Otherwise, the indentation is:
315
276
:override 'keep
316
277
`((quote_expression) @julia-ts-quoted-symbol-face)
317
278
279
+ :language 'julia
280
+ :feature 'string
281
+ '(((escape_sequence) @font-lock-escape-face)
282
+ ((prefixed_string_literal prefix: _ @prefix) @font-lock-regexp-face
283
+ (:equal " r" @prefix)))
284
+
318
285
:language 'julia
319
286
:feature 'string
320
287
:override 'keep
@@ -432,6 +399,20 @@ Return nil if there is no name or if NODE is not a defun node."
432
399
(lambda (child )
433
400
(equal (treesit-node-type child) type)))))
434
401
402
+ (defun julia-ts--fundef-name-p (node )
403
+ " Return non-nil if NODE is the name of a function definition.
404
+ NODE is recognized as such if it has an ancestor that is either a
405
+ `signature' (long syntax) or an `assignment' (short syntax), and
406
+ the first child of this ancestor is also an ancestor."
407
+ (let ((prev node))
408
+ (treesit-parent-until
409
+ node
410
+ (lambda (ancestor )
411
+ (prog1
412
+ (and (member (treesit-node-type ancestor) '(" signature" " assignment" ))
413
+ (equal (treesit-node-child ancestor 0 ) prev))
414
+ (setq prev ancestor))))))
415
+
435
416
;;;### autoload
436
417
(add-to-list 'auto-mode-alist '(" \\ .jl\\ '" . julia-ts-mode))
437
418
0 commit comments