@@ -144,23 +144,57 @@ Otherwise, the indentation is:
144144 (treesit-font-lock-rules
145145 :language 'julia
146146 :feature 'assignment
147- `((assignment :anchor [(identifier) (operator)] @font-lock- variable-name-face)
147+ `(; ; regular variable assignments
148148 (assignment
149149 :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+ (assignment
155+ :anchor
156+ (typed_expression (identifier) @font-lock-variable-name-face " ::" ))
157+ ; ; open tuple assignments (comma separated variables without parentheses)
158+ (assignment
159+ :anchor
160+ (open_tuple (identifier) @font-lock-variable-name-face))
153161 (assignment
154162 :anchor
155163 (open_tuple
156- (field_expression
157- value: (identifier) " ." (identifier) @font-lock-variable-name-face)))
158- (local_statement (identifier) @font-lock-variable-name-face)
164+ (field_expression " ." (identifier) @font-lock-variable-name-face)))
165+ (assignment
166+ :anchor
167+ (open_tuple
168+ (typed_expression (identifier) @font-lock-variable-name-face " ::" )))
169+ (assignment
170+ :anchor
171+ (open_tuple
172+ (splat_expression (identifier) @font-lock-variable-name-face)))
173+ ; ; closed tuple assignments (comma separated variables with parentheses)
174+ (assignment
175+ :anchor
176+ (tuple_expression (identifier) @font-lock-variable-name-face))
177+ (assignment
178+ :anchor
179+ (tuple_expression
180+ (field_expression " ." (identifier) @font-lock-variable-name-face)))
181+ (assignment
182+ :anchor
183+ (tuple_expression
184+ (typed_expression (identifier) @font-lock-variable-name-face " ::" )))
185+ (assignment
186+ :anchor
187+ (tuple_expression
188+ (splat_expression (identifier) @font-lock-variable-name-face)))
189+ ; ; let blocks
159190 (let_statement :anchor (identifier) @font-lock-variable-name-face)
160191 ((let_statement _ @comma :anchor (identifier) @font-lock-variable-name-face)
161192 (:equal " ," @comma))
162193 (let_binding :anchor (identifier) @font-lock-variable-name-face)
194+ ; ; local and global statements
195+ (local_statement (identifier) @font-lock-variable-name-face)
163196 (global_statement (identifier) @font-lock-variable-name-face)
197+ ; ; named (keyword) argument names with assigned values
164198 (named_argument (identifier) @julia-ts-keyword-argument-face (operator)))
165199
166200 :language 'julia
@@ -177,81 +211,27 @@ Otherwise, the indentation is:
177211
178212 :language 'julia
179213 :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))))
214+ `(; ; function declaration
203215 (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))))
216+ (signature (identifier) @font-lock-function-name-face))
217+ ; ; function definitions (long and short syntax)
218+ (call_expression
219+ [(identifier) (operator)] @font-lock-function-name-face
220+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
221+ (call_expression
222+ (parenthesized_expression
223+ [(identifier) (operator)] @font-lock-function-name-face)
224+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
225+ (call_expression
226+ (field_expression " ." [(identifier) (operator)] @font-lock-function-name-face)
227+ (:pred julia-ts--fundef-name-p @font-lock-function-name-face))
228+ ; ; binary operator definition as assignment
252229 (assignment
253230 :anchor
254- (binary_expression _ (operator) @font-lock-function-name-face)))
231+ (binary_expression _ (operator) @font-lock-function-name-face))
232+ ; ; struct/abstract type/primitive type definitions
233+ (type_head (identifier) @font-lock-type-face)
234+ (type_head (binary_expression (identifier) @font-lock-type-face)))
255235
256236 :language 'julia
257237 :feature 'error
@@ -315,6 +295,12 @@ Otherwise, the indentation is:
315295 :override 'keep
316296 `((quote_expression) @julia-ts-quoted-symbol-face)
317297
298+ :language 'julia
299+ :feature 'string
300+ '(((escape_sequence) @font-lock-escape-face)
301+ ((prefixed_string_literal prefix: _ @prefix) @font-lock-regexp-face
302+ (:equal " r" @prefix)))
303+
318304 :language 'julia
319305 :feature 'string
320306 :override 'keep
@@ -432,6 +418,20 @@ Return nil if there is no name or if NODE is not a defun node."
432418 (lambda (child )
433419 (equal (treesit-node-type child) type)))))
434420
421+ (defun julia-ts--fundef-name-p (node )
422+ " Return non-nil if NODE is the name of a function definition.
423+ NODE is recognized as such if it has an ancestor that is either a
424+ `signature' (long syntax) or an `assignment' (short syntax), and
425+ the first child of this ancestor is also an ancestor."
426+ (let ((prev node))
427+ (treesit-parent-until
428+ node
429+ (lambda (ancestor )
430+ (prog1
431+ (and (member (treesit-node-type ancestor) '(" signature" " assignment" ))
432+ (equal (treesit-node-child ancestor 0 ) prev))
433+ (setq prev ancestor))))))
434+
435435;;;### autoload
436436(add-to-list 'auto-mode-alist '(" \\ .jl\\ '" . julia-ts-mode))
437437
0 commit comments