@@ -144,23 +144,24 @@ 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)
148
- (assignment
149
- :anchor
150
- (field_expression
151
- value: (identifier) " ." (identifier) @font-lock-variable-name-face))
152
- (assignment (open_tuple (identifier) @font-lock-variable-name-face))
153
- (assignment
154
- :anchor
155
- (open_tuple
156
- (field_expression
157
- value: (identifier) " ." (identifier) @font-lock-variable-name-face)))
158
- (local_statement (identifier) @font-lock-variable-name-face)
147
+ `(; ; plain assignments
148
+ ([(identifier) (operator)] @font-lock-variable-name-face @lhs
149
+ (:pred julia-ts--assignment-left-side-p @lhs))
150
+ ; ; qualified name assignments
151
+ ((field_expression " ." (identifier) @font-lock-variable-name-face) @lhs
152
+ (:pred julia-ts--assignment-left-side-p @lhs))
153
+ ; ; typed assignments
154
+ ((typed_expression (identifier) @font-lock-variable-name-face " ::" ) @lhs
155
+ (:pred julia-ts--assignment-left-side-p @lhs))
156
+ ; ; let blocks
159
157
(let_statement :anchor (identifier) @font-lock-variable-name-face)
160
158
((let_statement _ @comma :anchor (identifier) @font-lock-variable-name-face)
161
159
(:equal " ," @comma))
162
160
(let_binding :anchor (identifier) @font-lock-variable-name-face)
161
+ ; ; local and global statements
162
+ (local_statement (identifier) @font-lock-variable-name-face)
163
163
(global_statement (identifier) @font-lock-variable-name-face)
164
+ ; ; named (keyword) argument names with assigned values
164
165
(named_argument (identifier) @julia-ts-keyword-argument-face (operator)))
165
166
166
167
:language 'julia
@@ -177,81 +178,27 @@ Otherwise, the indentation is:
177
178
178
179
:language 'julia
179
180
:feature 'definition
180
- `((function_definition
181
- (signature (identifier) @font-lock-function-name-face))
181
+ `(; ; function declaration
182
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))))
203
- (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))))
183
+ (signature (identifier) @font-lock-function-name-face))
184
+ ; ; function definitions (long and short syntax)
185
+ (call_expression
186
+ [(identifier) (operator)] @font-lock-function-name-face
187
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
188
+ (call_expression
189
+ (parenthesized_expression
190
+ [(identifier) (operator)] @font-lock-function-name-face)
191
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
192
+ (call_expression
193
+ (field_expression " ." [(identifier) (operator)] @font-lock-function-name-face)
194
+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
195
+ ; ; binary operator definition as assignment
252
196
(assignment
253
197
:anchor
254
- (binary_expression _ (operator) @font-lock-function-name-face)))
198
+ (binary_expression _ (operator) @font-lock-function-name-face))
199
+ ; ; struct/abstract type/primitive type definitions
200
+ (type_head (identifier) @font-lock-type-face)
201
+ (type_head (binary_expression (identifier) @font-lock-type-face)))
255
202
256
203
:language 'julia
257
204
:feature 'error
@@ -315,6 +262,12 @@ Otherwise, the indentation is:
315
262
:override 'keep
316
263
`((quote_expression) @julia-ts-quoted-symbol-face)
317
264
265
+ :language 'julia
266
+ :feature 'string
267
+ '(((escape_sequence) @font-lock-escape-face)
268
+ ((prefixed_string_literal prefix: _ @prefix) @font-lock-regexp-face
269
+ (:equal " r" @prefix)))
270
+
318
271
:language 'julia
319
272
:feature 'string
320
273
:override 'keep
@@ -432,6 +385,33 @@ Return nil if there is no name or if NODE is not a defun node."
432
385
(lambda (child )
433
386
(equal (treesit-node-type child) type)))))
434
387
388
+ (defun julia-ts--assignment-left-side-p (node )
389
+ " Return non-nil if NODE is the left hand side of an `assignment' .
390
+ It may be wrapped (within the `'assignment' ) in an `open_tuple'
391
+ or a `tuple_expression' (but only one of those two), and/or a
392
+ `splat_expression' as well."
393
+ (let* ((p1 (treesit-node-parent node))
394
+ (p2 (if (equal (treesit-node-type p1) " splat_expression" )
395
+ (treesit-node-parent p1) p1))
396
+ (p3 (if (member (treesit-node-type p2) '(" open_tuple" " tuple_expression" ))
397
+ (treesit-node-parent p2) p2)))
398
+ (and (equal (treesit-node-type p3) " assignment" )
399
+ (member (treesit-node-child p3 0 ) (list p2 p1 node)))))
400
+
401
+ (defun julia-ts--fundef-name-p (node )
402
+ " Return non-nil if NODE is the name of a function definition.
403
+ NODE is recognized as such if it has an ancestor that is either a
404
+ `signature' (long syntax) or an `assignment' (short syntax), via
405
+ the ancestor's first child."
406
+ (let ((prev node))
407
+ (treesit-parent-until
408
+ node
409
+ (lambda (ancestor )
410
+ (prog1
411
+ (and (member (treesit-node-type ancestor) '(" signature" " assignment" ))
412
+ (equal (treesit-node-child ancestor 0 ) prev))
413
+ (setq prev ancestor))))))
414
+
435
415
;;;### autoload
436
416
(add-to-list 'auto-mode-alist '(" \\ .jl\\ '" . julia-ts-mode))
437
417
0 commit comments