diff --git a/runtime/queries/julia/highlights.scm b/runtime/queries/julia/highlights.scm index 318488888..c4f6999ac 100644 --- a/runtime/queries/julia/highlights.scm +++ b/runtime/queries/julia/highlights.scm @@ -1,112 +1,142 @@ +; ---------- +; Primitives +; ---------- + +[ + (line_comment) + (block_comment) +] @comment + +(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|missing|Inf|NaN)$")) +(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true")) +(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false")) + +(integer_literal) @constant.numeric.integer +(float_literal) @constant.numeric.float + +(character_literal) @constant.character +(escape_sequence) @constant.character.escape (string_literal) @string (prefixed_string_literal - prefix: (identifier) @constant.builtin) + prefix: (identifier) @function.macro) @string -(macro_identifier) @function.macro -(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight -(macro_definition - name: (identifier) @function.macro - ["macro" "end" @keyword]) +(quote_expression + (identifier) @string.special.symbol) + +; ------------------- +; Modules and Imports +; ------------------- + +(module_definition + name: (identifier) @namespace) + +(import_statement + (identifier) @namespace) + +(selected_import + . (identifier) @namespace) + +(scoped_identifier + (identifier) @namespace) + +; ----- +; Types +; ----- + +(abstract_definition + name: (identifier) @type) + +(primitive_definition + name: (identifier) @type) -(field_expression - (identifier) - (identifier) @variable.other.member .) +(struct_definition + name: (identifier) @type) + +(struct_definition + . (_) + (identifier) @variable.other.member) + +(struct_definition + . (_) + (typed_expression + . (identifier) @variable.other.member)) + +(type_parameter_list + (identifier) @type) + +(constrained_parameter + (identifier) @type) + +(subtype_clause + (identifier) @type) + +(typed_expression + (identifier) @type . ) + +(parameterized_identifier + (identifier) @type) + +(type_argument_list + (identifier) @type) + +; ------------------- +; Function definition +; ------------------- (function_definition name: (identifier) @function) -(call_expression - (identifier) @function) -(call_expression - (field_expression (identifier) @function.method .)) -(broadcast_call_expression - (identifier) @function) -(broadcast_call_expression - (field_expression (identifier) @function.method .)) + (parameter_list (identifier) @variable.parameter) -(parameter_list - (optional_parameter . - (identifier) @variable.parameter)) -(typed_parameter - (identifier) @variable.parameter - (identifier) @type) -(type_parameter_list - (identifier) @type) + (typed_parameter (identifier) @variable.parameter - (parameterized_identifier) @type) -(function_expression + (identifier)? @type) + +(optional_parameter . (identifier) @variable.parameter) -(spread_parameter) @variable.parameter + (spread_parameter (identifier) @variable.parameter) -(named_argument - . (identifier) @variable.parameter) -(argument_list - (typed_expression - (identifier) @variable.parameter - (identifier) @type)) -(argument_list - (typed_expression - (identifier) @variable.parameter - (parameterized_identifier) @type)) -;; Symbol expressions (:my-wanna-be-lisp-keyword) -(quote_expression - (identifier)) @string.special.symbol +(function_expression + . (identifier) @variable.parameter) -;; Parsing error! foo (::Type) get's parsed as two quote expressions -(argument_list - (quote_expression - (quote_expression - (identifier) @type))) +; --------------- +; Functions calls +; --------------- -(type_argument_list - (identifier) @type) -(parameterized_identifier (_)) @type -(argument_list - (typed_expression . (identifier) @variable.parameter)) +(call_expression + (identifier) @function) -(typed_expression - (identifier) @type .) -(typed_expression - (parameterized_identifier) @type .) +(broadcast_call_expression + (identifier) @function) -(struct_definition - name: (identifier) @type) +(call_expression + (field_expression (identifier) @function .)) -(integer_literal) @constant.numeric.integer -(float_literal) @constant.numeric.float +(broadcast_call_expression + (field_expression (identifier) @function .)) + +; ------ +; Macros +; ------ + +(macro_definition + name: (identifier) @function.macro) -(range_expression - (identifier) @constant.numeric.integer - (eq? @constant.numeric.integer "end")) -(range_expression - (_ - (identifier) @constant.numeric.integer - (eq? @constant.numeric.integer "end"))) -(coefficient_expression - [ - (integer_literal) - (float_literal) - ] - (identifier) @constant.builtin) - -;; TODO: operators. -;; Those are a bit difficult to implement since the respective nodes are hidden right now (_power_operator) -;; and heavily use Unicode chars (support for those are bad in vim/lua regexes) -;[; - ;(power_operator); - ;(times_operator); - ;(plus_operator); - ;(arrow_operator); - ;(comparison_operator); - ;(assign_operator); -;] @operator ; - -"end" @keyword +(macro_identifier + "@" @function.macro + (identifier) @function.macro) + +; -------- +; Keywords +; -------- + +(function_definition + ["function" "end"] @keyword.function) (if_statement ["if" "end"] @keyword.control.conditional) @@ -117,36 +147,6 @@ (ternary_expression ["?" ":"] @keyword.control.conditional) -(function_definition ["function" "end"] @keyword.function) - -[ - (line_comment) - (block_comment) -] @comment - -[ - "const" - "return" - "macro" - "struct" - "primitive" - "type" -] @keyword - -((identifier) @keyword (match? @keyword "global|local")) - -(compound_expression - ["begin" "end"] @keyword) -(try_statement - ["try" "end" ] @keyword.control.exception) -(finally_clause - "finally" @keyword.control.exception) -(catch_clause - "catch" @keyword.control.exception) -(quote_statement - ["quote" "end"] @keyword) -(let_statement - ["let" "end"] @keyword) (for_statement ["for" "end"] @keyword.control.repeat) (while_statement @@ -157,33 +157,90 @@ "in" @keyword.control.repeat) (for_clause "for" @keyword.control.repeat) -(do_clause - ["do" "end"] @keyword) -(export_statement - ["export"] @keyword.control.import) +(try_statement + ["try" "end" ] @keyword.control.exception) +(finally_clause + "finally" @keyword.control.exception) +(catch_clause + "catch" @keyword.control.exception) [ - "using" - "module" + "export" "import" + "using" ] @keyword.control.import -((identifier) @keyword.control.import (#eq? @keyword.control.import "baremodule")) +[ + "abstract" + "begin" + "const" + "do" + "end" + "let" + "macro" + "module" + "mutable" + "primitive" + "quote" + "return" + "struct" + "type" +] @keyword + +; TODO: fix this +((identifier) @keyword (match? @keyword "global|local")) -(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|Inf|NaN)$")) -(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true")) -(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false")) +; --------- +; Operators +; --------- + +[ + (operator) + "::" + "<:" + ":" + "=>" + "..." + "$" +] @operator + +; ------------ +; Punctuations +; ------------ + +[ + "." + "," + ";" +] @punctuation.delimiter + +[ + "[" + "]" + "(" + ")" + "{" + "}" +] @punctuation.bracket + +; --------------------- +; Remaining identifiers +; --------------------- + +; could also be namespace but this should cover the majority +(field_expression + . (_) + (identifier) @variable.other.member) +(const_statement + (variable_declaration + . (identifier) @constant)) -["::" ":" "." "," "..."] @punctuation.delimiter -["[" "]" "(" ")" "{" "}"] @punctuation.bracket +((identifier) @type + (match? @type "([A-Z][a-z0-9]+)+$")) -["="] @operator +((identifier) @constant + (match? @constant "^[A-Z][A-Z0-9_]+$")) (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][^_]")) -((identifier) @constant - (match? @constant "^[A-Z][A-Z_]{2}[A-Z_]*$")) diff --git a/runtime/queries/julia/injections.scm b/runtime/queries/julia/injections.scm index 3eab231fa..caed916f3 100644 --- a/runtime/queries/julia/injections.scm +++ b/runtime/queries/julia/injections.scm @@ -1,8 +1,16 @@ -; ((string_literal) @injection.content -; (#set! injection.language "markdown")) +( + (string_literal) @injection.content + (#set! injection.language "markdown")) -; ((line_comment) @injection.content -; (#set! injection.language "comment")) +( + [ + (line_comment) + (block_comment) + ] @injection.content + (#set! injection.language "comment")) -; ((block_comment) @injection.content -; (#set! injection.language "comment")) +( + (prefixed_string_literal + prefix: (identifier) @function.macro) @injection.content + (#eq? @function.macro "re") + (#set! injection.language "regex")) diff --git a/runtime/queries/julia/locals.scm b/runtime/queries/julia/locals.scm index d5ac794e8..07b96f2c6 100644 --- a/runtime/queries/julia/locals.scm +++ b/runtime/queries/julia/locals.scm @@ -1,59 +1,43 @@ +; ----------- +; Definitions +; ----------- +; Imports (import_statement - (identifier) @definition.import) -(variable_declaration - (identifier) @local.definition) -(variable_declaration - (tuple_expression - (identifier) @local.definition)) -(for_binding - (identifier) @local.definition) -(for_binding - (tuple_expression - (identifier) @local.definition)) - -(assignment_expression - (tuple_expression - (identifier) @local.definition)) -(assignment_expression - (bare_tuple_expression - (identifier) @local.definition)) -(assignment_expression - (identifier) @local.definition) - -(type_parameter_list - (identifier) @definition.type) -(type_argument_list - (identifier) @definition.type) -(struct_definition - name: (identifier) @definition.type) + (identifier) @local.definition) + +; Constants +(const_statement + (variable_declaration + . (identifier) @local.definition)) +; Parameters (parameter_list - (identifier) @definition.parameter) + (identifier) @local.definition) + (typed_parameter - (identifier) @definition.parameter - (identifier)) -(function_expression - . (identifier) @definition.parameter) -(argument_list - (typed_expression - (identifier) @definition.parameter - (identifier))) -(spread_parameter - (identifier) @definition.parameter) + . (identifier) @local.definition) -(function_definition - name: (identifier) @definition.function) @local.scope -(macro_definition - name: (identifier) @definition.macro) @local.scope +(optional_parameter . + (identifier) @local.definition) -(identifier) @local.reference +(spread_parameter + (identifier) @local.definition) + +(function_expression + . (identifier) @local.definition) + +; ------ +; Scopes +; ------ [ - (try_statement) - (finally_clause) - (quote_statement) - (let_statement) - (compound_expression) - (for_statement) + (function_definition) + (macro_definition) ] @local.scope + +; ---------- +; References +; ---------- + +(identifier) @local.reference