on master help sign in
Julia queries: prevent constructors to be highlighted as functions

Also improves the captures of the remaining identifiers.

commit26b2f0a1b5a1bb6cd83f16f6019d903312999bb9 authorChristoph Horn <christoph-horn@hotmail.de> dateWed 24 Aug 2022, 10:32 (4 years ago) parent5806db1
1 file changed+37−19
runtime/queries/julia/highlights.scm+37−19
runtime/queries/julia/highlights.scm+37−19
@@ -85,8 +85,11 @@
8585; Function definition
8686; -------------------
8787
88−(function_definition
89− name: (identifier) @function)
88+(
89+ (function_definition
90+ name: (identifier) @function)
91+ ; prevent constructors (PascalCase) to be highlighted as functions
92+ (#match? @function "^[^A-Z]"))
9093
9194(parameter_list
9295 (identifier) @variable.parameter)
@@ -108,17 +111,26 @@
108111; Functions calls
109112; ---------------
110113
111−(call_expression
112− (identifier) @function)
114+(
115+ (call_expression
116+ (identifier) @function)
117+ ; prevent constructors (PascalCase) to be highlighted as functions
118+ (#match? @function "^[^A-Z]"))
113119
114−(broadcast_call_expression
115− (identifier) @function)
120+(
121+ (broadcast_call_expression
122+ (identifier) @function)
123+ (#match? @function "^[^A-Z]"))
116124
117−(call_expression
118− (field_expression (identifier) @function .))
125+(
126+ (call_expression
127+ (field_expression (identifier) @function .))
128+ (#match? @function "^[^A-Z]"))
119129
120−(broadcast_call_expression
121− (field_expression (identifier) @function .))
130+(
131+ (broadcast_call_expression
132+ (field_expression (identifier) @function .))
133+ (#match? @function "^[^A-Z]"))
122134
123135; ------
124136; Macros
@@ -228,19 +240,25 @@
228240; Remaining identifiers
229241; ---------------------
230242
231−; could also be namespace but this should cover the majority
232−(field_expression
233− . (_)
234− (identifier) @variable.other.member)
235−
236243(const_statement
237244 (variable_declaration
238245 . (identifier) @constant))
239246
240−((identifier) @type
241− (match? @type "([A-Z][a-z0-9]+)+$"))
247+; SCREAMING_SNAKE_CASE
248+(
249+ (identifier) @constant
250+ (match? @constant "^[A-Z][A-Z0-9_]*$"))
242251
243−((identifier) @constant
244− (match? @constant "^[A-Z][A-Z0-9_]+$"))
252+; remaining identifiers that start with capital letters should be types (PascalCase)
253+(
254+ (identifier) @type
255+ (match? @type "^[A-Z]"))
256+
257+; Field expressions are either module content or struct fields.
258+; Module types and constants should already be captured, so this
259+; assumes the remaining identifiers to be struct fields.
260+(field_expression
261+ (_)
262+ (identifier) @variable.other.member)
245263
246264(identifier) @variable