From 27bbb64f8773066371c3f844e9bdad4c942bcdad Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Sun, 9 Oct 2022 23:58:05 -0500 Subject: refactor(highlights/julia): Update definitions See https://github.com/tree-sitter/tree-sitter-julia/pull/54 Remove a bunch of patterns with `argument_list`. No longer necessary with `short_function_definition`. Other minor changes including: - Add boolean literals See https://github.com/tree-sitter/tree-sitter-julia/pull/44 - Update highlights for operators (for bindings, type operators, etc) - Update lockfile --- queries/julia/highlights.scm | 231 +++++++++++++++++++++++++------------------ 1 file changed, 135 insertions(+), 96 deletions(-) (limited to 'queries/julia/highlights.scm') diff --git a/queries/julia/highlights.scm b/queries/julia/highlights.scm index 1b7e5b72..f0e53c2c 100644 --- a/queries/julia/highlights.scm +++ b/queries/julia/highlights.scm @@ -1,106 +1,113 @@ -(identifier) @variable +;;; Identifiers -(operator) @operator -(range_expression ":" @operator) -(pair_expression "=>" @operator) +(identifier) @variable -;; In case you want type highlighting based on Julia naming conventions (this might collide with mathematical notation) -;((identifier) @type ; exception: mark `A_foo` sort of identifiers as variables - ;(match? @type "^[A-Z][^_]")) +; ;; If you want type highlighting based on Julia naming conventions (this might collide with mathematical notation) +; ((identifier) @type +; (match? @type "^[A-Z][^_]")) ; exception: Highlight `A_foo` sort of identifiers as variables (macro_identifier) @function.macro -(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight +(macro_identifier + (identifier) @function.macro) ; for any one using the variable highlight + (macro_definition - name: (identifier) @function.macro - ["macro" "end" @keyword]) + name: (identifier) @function.macro) + +(quote_expression ":" (identifier)) @symbol + + +;;; Fields and indexes (field_expression - (identifier) (identifier) @field .) +(subscript_expression + (_) + (range_expression + (identifier) @constant.builtin .) + (#eq? @constant.builtin "end")) + + +;;; Function names + +;; definitions + (function_definition name: (identifier) @function) +(short_function_definition + name: (identifier) @function) + +(function_definition + name: (scoped_identifier (identifier) @function .)) +(short_function_definition + name: (scoped_identifier (identifier) @function .)) + +;; calls + (call_expression (identifier) @function.call) (call_expression - (field_expression (identifier) @method.call .)) + (field_expression (identifier) @function.call .)) + (broadcast_call_expression (identifier) @function.call) (broadcast_call_expression - (field_expression (identifier) @method.call .)) + (field_expression (identifier) @function.call .)) + + +;;; Parameters + (parameter_list (identifier) @parameter) -(parameter_list - (optional_parameter . - (identifier) @parameter)) +(optional_parameter . + (identifier) @parameter) +(slurp_parameter + (identifier) @parameter) + (typed_parameter - (identifier) @parameter - (identifier) @type) -(type_parameter_list - (identifier) @type) + parameter: (identifier) @parameter + type: (_) @type) (typed_parameter - (identifier) @parameter - (parameterized_identifier) @type) + type: (_) @type) + (function_expression - . (identifier) @parameter) -(spread_parameter) @parameter -(spread_parameter - (identifier) @parameter) -(named_argument - . (identifier) @parameter) -(argument_list - (typed_expression - (identifier) @parameter - (identifier) @type)) -(argument_list - (typed_expression - (identifier) @parameter - (parameterized_identifier) @type)) - -;; Symbol expressions (:my-wanna-be-lisp-keyword) -(quote_expression - (identifier)) @symbol - -;; Parsing error! foo (::Type) gets parsed as two quote expressions -(argument_list - (quote_expression - (quote_expression - (identifier) @type))) + . (identifier) @parameter) ; Single parameter arrow functions -(type_argument_list - (identifier) @type) -(parameterized_identifier (_)) @type -(argument_list - (typed_expression . (identifier) @parameter)) -(typed_expression - (identifier) @type .) -(typed_expression - (parameterized_identifier) @type .) +;;; Types + +;; Definitions (abstract_definition name: (identifier) @type) +(primitive_definition + name: (identifier) @type) (struct_definition name: (identifier) @type) -(subscript_expression - (_) - (range_expression - (identifier) @constant.builtin .) - (#eq? @constant.builtin "end")) +;; Annotations -"end" @keyword +(parameterized_identifier (_) @type) -(if_statement - ["if" "end"] @conditional) -(elseif_clause - ["elseif"] @conditional) -(else_clause - ["else"] @conditional) -(ternary_expression - ["?" ":"] @conditional) +(type_parameter_list + (identifier) @type) + +(type_argument_list + (identifier) @type) -(function_definition ["function" "end"] @keyword.function) +(typed_expression + (identifier) @type .) + +(function_definition + return_type: (identifier) @type) +(short_function_definition + return_type: (identifier) @type) + +(where_clause + (identifier) @type) ; where clause without braces + + +;;; Keywords [ "abstract" @@ -110,51 +117,91 @@ "struct" "type" "mutable" + "where" ] @keyword -"return" @keyword.return +"end" @keyword -((identifier) @keyword (#any-of? @keyword "global" "local")) +((identifier) @keyword (#any-of? @keyword "global" "local")) ; Grammar error (compound_expression ["begin" "end"] @keyword) +(quote_statement + ["quote" "end"] @keyword) +(let_statement + ["let" "end"] @keyword) + +(if_statement + ["if" "end"] @conditional) +(elseif_clause + ["elseif"] @conditional) +(else_clause + ["else"] @conditional) +(ternary_expression + ["?" ":"] @conditional) + (try_statement - ["try" "end" ] @exception) + ["try" "end"] @exception) (finally_clause "finally" @exception) (catch_clause "catch" @exception) -(quote_statement - ["quote" "end"] @keyword) -(let_statement - ["let" "end"] @keyword) + (for_statement ["for" "end"] @repeat) (while_statement ["while" "end"] @repeat) -(break_statement) @repeat -(continue_statement) @repeat (for_clause "for" @repeat) +[ + (break_statement) + (continue_statement) +] @repeat + +(module_definition + ["module" "baremodule" "end"] @include) +(import_statement + ["import" "using"] @include) +(export_statement + "export" @include) + +(macro_definition + ["macro" "end" @keyword]) + +(function_definition + ["function" "end"] @keyword.function) (do_clause - ["do" "end"] @keyword) + ["do" "end"] @keyword.function) +(function_expression + "->" @keyword.function) +(return_statement + "return" @keyword.return) -"in" @keyword.operator -(export_statement - ["export"] @include) +;;; Operators & Punctuation -(import_statement - ["import" "using"] @include) +(operator) @operator +(for_binding ["in" "=" "∈"] @operator) +(pair_expression "=>" @operator) +(range_expression ":" @operator) -(module_definition - ["module" "end"] @include) +(slurp_parameter "..." @operator) +(spread_expression "..." @operator) -((identifier) @include (#eq? @include "baremodule")) +"." @operator +["::" "<:"] @operator + +["," ";"] @punctuation.delimiter +["(" ")" "[" "]" "{" "}"] @punctuation.bracket ;;; Literals +[ + (true) + (false) +] @boolean + (integer_literal) @number (float_literal) @float @@ -162,9 +209,6 @@ (#any-of? @float "NaN" "NaN16" "NaN32" "Inf" "Inf16" "Inf32")) -((identifier) @boolean - (#any-of? @boolean "true" "false")) - ((identifier) @constant.builtin (#any-of? @constant.builtin "nothing" "missing")) @@ -184,8 +228,3 @@ (block_comment) ] @comment -;;; Punctuation - -(quote_expression ":" @symbol) -["::" "." "," "..."] @punctuation.delimiter -["[" "]" "(" ")" "{" "}"] @punctuation.bracket -- cgit v1.2.3 From f6bc84dabdf6e201c25df2a1f5e1bb5748c833d1 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 6 Nov 2022 11:03:23 +0100 Subject: fix: update julia queries to parser change --- queries/julia/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'queries/julia/highlights.scm') diff --git a/queries/julia/highlights.scm b/queries/julia/highlights.scm index f0e53c2c..96ca1c49 100644 --- a/queries/julia/highlights.scm +++ b/queries/julia/highlights.scm @@ -124,7 +124,7 @@ ((identifier) @keyword (#any-of? @keyword "global" "local")) ; Grammar error -(compound_expression +(compound_statement ["begin" "end"] @keyword) (quote_statement ["quote" "end"] @keyword) -- cgit v1.2.3 From 692432df294ef3881f450dc80839e21c978cde28 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 12 Nov 2022 10:28:50 +0100 Subject: julia: update queries to parser change --- queries/julia/highlights.scm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'queries/julia/highlights.scm') diff --git a/queries/julia/highlights.scm b/queries/julia/highlights.scm index 96ca1c49..8d30ff55 100644 --- a/queries/julia/highlights.scm +++ b/queries/julia/highlights.scm @@ -21,7 +21,7 @@ (field_expression (identifier) @field .) -(subscript_expression +(index_expression (_) (range_expression (identifier) @constant.builtin .) @@ -87,14 +87,11 @@ ;; Annotations -(parameterized_identifier (_) @type) +(parametrized_type_expression (_) @type) (type_parameter_list (identifier) @type) -(type_argument_list - (identifier) @type) - (typed_expression (identifier) @type .) -- cgit v1.2.3