Julia queries: major refactoring of `highlights.scm`, add regex injections, locals

pull/9/head
Christoph Horn 2 years ago committed by Michael Davis
parent 77f11bf272
commit f5c00b9bc9

@ -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 (string_literal) @string
(prefixed_string_literal (prefixed_string_literal
prefix: (identifier) @constant.builtin) prefix: (identifier) @function.macro) @string
(macro_identifier) @function.macro (quote_expression
(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight (identifier) @string.special.symbol)
(macro_definition
name: (identifier) @function.macro ; -------------------
["macro" "end" @keyword]) ; 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 (struct_definition
(identifier) name: (identifier) @type)
(identifier) @variable.other.member .)
(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 (function_definition
name: (identifier) @function) 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 (parameter_list
(identifier) @variable.parameter) (identifier) @variable.parameter)
(parameter_list
(optional_parameter .
(identifier) @variable.parameter))
(typed_parameter
(identifier) @variable.parameter
(identifier) @type)
(type_parameter_list
(identifier) @type)
(typed_parameter (typed_parameter
(identifier) @variable.parameter (identifier) @variable.parameter
(parameterized_identifier) @type) (identifier)? @type)
(function_expression
(optional_parameter
. (identifier) @variable.parameter) . (identifier) @variable.parameter)
(spread_parameter) @variable.parameter
(spread_parameter (spread_parameter
(identifier) @variable.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) (function_expression
(quote_expression . (identifier) @variable.parameter)
(identifier)) @string.special.symbol
;; Parsing error! foo (::Type) get's parsed as two quote expressions ; ---------------
(argument_list ; Functions calls
(quote_expression ; ---------------
(quote_expression
(identifier) @type)))
(type_argument_list (call_expression
(identifier) @type) (identifier) @function)
(parameterized_identifier (_)) @type
(argument_list
(typed_expression . (identifier) @variable.parameter))
(typed_expression (broadcast_call_expression
(identifier) @type .) (identifier) @function)
(typed_expression
(parameterized_identifier) @type .)
(struct_definition (call_expression
name: (identifier) @type) (field_expression (identifier) @function .))
(integer_literal) @constant.numeric.integer (broadcast_call_expression
(float_literal) @constant.numeric.float (field_expression (identifier) @function .))
; ------
; Macros
; ------
(macro_definition
name: (identifier) @function.macro)
(range_expression (macro_identifier
(identifier) @constant.numeric.integer "@" @function.macro
(eq? @constant.numeric.integer "end")) (identifier) @function.macro)
(range_expression
(_ ; --------
(identifier) @constant.numeric.integer ; Keywords
(eq? @constant.numeric.integer "end"))) ; --------
(coefficient_expression
[ (function_definition
(integer_literal) ["function" "end"] @keyword.function)
(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
(if_statement (if_statement
["if" "end"] @keyword.control.conditional) ["if" "end"] @keyword.control.conditional)
@ -117,36 +147,6 @@
(ternary_expression (ternary_expression
["?" ":"] @keyword.control.conditional) ["?" ":"] @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_statement
["for" "end"] @keyword.control.repeat) ["for" "end"] @keyword.control.repeat)
(while_statement (while_statement
@ -157,33 +157,90 @@
"in" @keyword.control.repeat) "in" @keyword.control.repeat)
(for_clause (for_clause
"for" @keyword.control.repeat) "for" @keyword.control.repeat)
(do_clause
["do" "end"] @keyword)
(export_statement (try_statement
["export"] @keyword.control.import) ["try" "end" ] @keyword.control.exception)
(finally_clause
"finally" @keyword.control.exception)
(catch_clause
"catch" @keyword.control.exception)
[ [
"using" "export"
"module"
"import" "import"
"using"
] @keyword.control.import ] @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")) ; Operators
(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false")) ; ---------
[
(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 ((identifier) @type
["[" "]" "(" ")" "{" "}"] @punctuation.bracket (match? @type "([A-Z][a-z0-9]+)+$"))
["="] @operator ((identifier) @constant
(match? @constant "^[A-Z][A-Z0-9_]+$"))
(identifier) @variable (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 (import_statement
(identifier) @definition.import) (identifier) @local.definition)
(variable_declaration
(identifier) @local.definition) ; Constants
(variable_declaration (const_statement
(tuple_expression (variable_declaration
(identifier) @local.definition)) . (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)
; Parameters
(parameter_list (parameter_list
(identifier) @definition.parameter) (identifier) @local.definition)
(typed_parameter (typed_parameter
(identifier) @definition.parameter . (identifier) @local.definition)
(identifier))
(function_expression
. (identifier) @definition.parameter)
(argument_list
(typed_expression
(identifier) @definition.parameter
(identifier)))
(spread_parameter
(identifier) @definition.parameter)
(function_definition (optional_parameter .
name: (identifier) @definition.function) @local.scope (identifier) @local.definition)
(macro_definition
name: (identifier) @definition.macro) @local.scope
(identifier) @local.reference (spread_parameter
(identifier) @local.definition)
(function_expression
. (identifier) @local.definition)
; ------
; Scopes
; ------
[ [
(try_statement) (function_definition)
(finally_clause) (macro_definition)
(quote_statement)
(let_statement)
(compound_expression)
(for_statement)
] @local.scope ] @local.scope
; ----------
; References
; ----------
(identifier) @local.reference

Loading…
Cancel
Save