Julia queries: major refactoring of highlights.scm
, add regex injections, locals
This commit is contained in:
parent
77f11bf272
commit
f5c00b9bc9
3 changed files with 253 additions and 204 deletions
runtime/queries/julia
|
@ -1,112 +1,142 @@
|
|||
; ----------
|
||||
; Primitives
|
||||
; ----------
|
||||
|
||||
(string_literal) @string
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @comment
|
||||
|
||||
(prefixed_string_literal
|
||||
prefix: (identifier) @constant.builtin)
|
||||
|
||||
(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])
|
||||
|
||||
(field_expression
|
||||
(identifier)
|
||||
(identifier) @variable.other.member .)
|
||||
|
||||
(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) @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
|
||||
|
||||
;; Parsing error! foo (::Type) get's parsed as two quote expressions
|
||||
(argument_list
|
||||
(quote_expression
|
||||
(quote_expression
|
||||
(identifier) @type)))
|
||||
|
||||
(type_argument_list
|
||||
(identifier) @type)
|
||||
(parameterized_identifier (_)) @type
|
||||
(argument_list
|
||||
(typed_expression . (identifier) @variable.parameter))
|
||||
|
||||
(typed_expression
|
||||
(identifier) @type .)
|
||||
(typed_expression
|
||||
(parameterized_identifier) @type .)
|
||||
|
||||
(struct_definition
|
||||
name: (identifier) @type)
|
||||
(((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
|
||||
|
||||
(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)
|
||||
(character_literal) @constant.character
|
||||
(escape_sequence) @constant.character.escape
|
||||
|
||||
;; 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 ;
|
||||
(string_literal) @string
|
||||
|
||||
"end" @keyword
|
||||
(prefixed_string_literal
|
||||
prefix: (identifier) @function.macro) @string
|
||||
|
||||
(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)
|
||||
|
||||
(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)
|
||||
|
||||
(parameter_list
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
(typed_parameter
|
||||
(identifier) @variable.parameter
|
||||
(identifier)? @type)
|
||||
|
||||
(optional_parameter
|
||||
. (identifier) @variable.parameter)
|
||||
|
||||
(spread_parameter
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
(function_expression
|
||||
. (identifier) @variable.parameter)
|
||||
|
||||
; ---------------
|
||||
; Functions calls
|
||||
; ---------------
|
||||
|
||||
(call_expression
|
||||
(identifier) @function)
|
||||
|
||||
(broadcast_call_expression
|
||||
(identifier) @function)
|
||||
|
||||
(call_expression
|
||||
(field_expression (identifier) @function .))
|
||||
|
||||
(broadcast_call_expression
|
||||
(field_expression (identifier) @function .))
|
||||
|
||||
; ------
|
||||
; Macros
|
||||
; ------
|
||||
|
||||
(macro_definition
|
||||
name: (identifier) @function.macro)
|
||||
|
||||
(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
|
||||
|
||||
(((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"))
|
||||
; TODO: fix this
|
||||
((identifier) @keyword (match? @keyword "global|local"))
|
||||
|
||||
; ---------
|
||||
; Operators
|
||||
; ---------
|
||||
|
||||
["::" ":" "." "," "..."] @punctuation.delimiter
|
||||
["[" "]" "(" ")" "{" "}"] @punctuation.bracket
|
||||
[
|
||||
(operator)
|
||||
"::"
|
||||
"<:"
|
||||
":"
|
||||
"=>"
|
||||
"..."
|
||||
"$"
|
||||
] @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))
|
||||
|
||||
((identifier) @type
|
||||
(match? @type "([A-Z][a-z0-9]+)+$"))
|
||||
|
||||
((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_]*$"))
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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)))
|
||||
. (identifier) @local.definition)
|
||||
|
||||
(optional_parameter .
|
||||
(identifier) @local.definition)
|
||||
|
||||
(spread_parameter
|
||||
(identifier) @definition.parameter)
|
||||
(identifier) @local.definition)
|
||||
|
||||
(function_definition
|
||||
name: (identifier) @definition.function) @local.scope
|
||||
(macro_definition
|
||||
name: (identifier) @definition.macro) @local.scope
|
||||
|
||||
(identifier) @local.reference
|
||||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue