Skip to content

Commit

Permalink
Julia queries: prevent constructors to be highlighted as functions
Browse files Browse the repository at this point in the history
Also improves the captures of the remaining identifiers.
  • Loading branch information
ChrHorn committed Aug 24, 2022
1 parent 0d41485 commit a31df36
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions runtime/queries/julia/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@
; Function definition
; -------------------

(function_definition
name: (identifier) @function)
(
(function_definition
name: (identifier) @function)
; prevent constructors (PascalCase) to be highlighted as functions
(#match? @function "^[^A-Z]")
)

(parameter_list
(identifier) @variable.parameter)
Expand All @@ -108,17 +112,30 @@
; Functions calls
; ---------------

(call_expression
(identifier) @function)

(broadcast_call_expression
(identifier) @function)

(call_expression
(field_expression (identifier) @function .))

(broadcast_call_expression
(field_expression (identifier) @function .))
(
(call_expression
(identifier) @function)
; prevent constructors (PascalCase) to be highlighted as functions
(#match? @function "^[^A-Z]")
)

(
(broadcast_call_expression
(identifier) @function)
(#match? @function "^[^A-Z]")
)

(
(call_expression
(field_expression (identifier) @function .))
(#match? @function "^[^A-Z]")
)

(
(broadcast_call_expression
(field_expression (identifier) @function .))
(#match? @function "^[^A-Z]")
)

; ------
; Macros
Expand Down Expand Up @@ -228,19 +245,23 @@
; Remaining identifiers
; ---------------------

; could also be namespace but this should cover the majority
(field_expression
. (_)
(identifier) @variable.other.member)

(const_statement
(variable_declaration
. (identifier) @constant))

; SCREAMING_SNAKE_CASE
((identifier) @constant
(match? @constant "^[A-Z][A-Z0-9_]*$"))

; remaining identifiers that start with capital letters should be types (PascalCase)
((identifier) @type
(match? @type "([A-Z][a-z0-9]+)+$"))
(match? @type "^[A-Z]"))

((identifier) @constant
(match? @constant "^[A-Z][A-Z0-9_]+$"))
; Field expressions are either module content or struct fields.
; Module types and constants should already be captured, so this
; assumes the remaining identifiers to be struct fields.
(field_expression
(_)
(identifier) @variable.other.member)

(identifier) @variable

0 comments on commit a31df36

Please # to comment.