From a31df367e41ba02bc1e50be8289fb3cb30cf31f0 Mon Sep 17 00:00:00 2001 From: Christoph Horn Date: Wed, 24 Aug 2022 10:32:08 +0200 Subject: [PATCH] Julia queries: prevent constructors to be highlighted as functions Also improves the captures of the remaining identifiers. --- runtime/queries/julia/highlights.scm | 63 ++++++++++++++++++---------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/runtime/queries/julia/highlights.scm b/runtime/queries/julia/highlights.scm index c4f6999ac4ca3..2affee773f96d 100644 --- a/runtime/queries/julia/highlights.scm +++ b/runtime/queries/julia/highlights.scm @@ -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) @@ -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 @@ -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