Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/julia/highlights.scm')
| -rw-r--r-- | runtime/queries/julia/highlights.scm | 573 |
1 files changed, 138 insertions, 435 deletions
diff --git a/runtime/queries/julia/highlights.scm b/runtime/queries/julia/highlights.scm index f473d2ca..7b7d426c 100644 --- a/runtime/queries/julia/highlights.scm +++ b/runtime/queries/julia/highlights.scm @@ -1,481 +1,184 @@ -; ------------ -; Variables identifiers -; ------------ -(identifier) @variable - -; Remaining identifiers that start with capital letters should be types (PascalCase) -( - (identifier) @type - (#match? @type "^[A-Z]")) - -; SCREAMING_SNAKE_CASE -( - (identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]*$")) - -(const_statement - (assignment - . (identifier) @constant)) - -; Field expressions are either module content or struct fields. -; Module types and constants should already be captured, so this -; assumes the remaining identifiers to be struct fields. -(field_expression - (_) - (identifier) @variable.other.member) - -(quote_expression - ":" @string.special.symbol - [ - (identifier) - (operator) - ] @string.special.symbol) +[ + (triple_string) + (string) +] @string -; ------ -; Macros -; ------ +(string + 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_identifier - "@" @function.macro - (identifier) @function.macro) - -; ------------------- -; Modules and Imports -; ------------------- - -(module_definition - name: (identifier) @namespace) - -(import_statement - (identifier) @namespace) - -(selected_import - . (identifier) @namespace) - -(scoped_identifier - (identifier) @namespace) - -; ------------------- -; Function definition -; ------------------- - -( - (function_definition - name: [ - (identifier) @function - (scoped_identifier - (identifier) @namespace - (identifier) @function) - ]) - ; prevent constructors (PascalCase) to be highlighted as functions - (#match? @function "^[^A-Z]")) - -( - (short_function_definition - name: [ - (identifier) @function - (scoped_identifier - (identifier) @namespace - (identifier) @function) - ]) - ; prevent constructors (PascalCase) to be highlighted as functions - (#match? @function "^[^A-Z]")) - -; --------------- -; Functions calls -; --------------- + name: (identifier) @function.macro + ["macro" "end" @keyword]) -( - (call_expression - (identifier) @function) - ; prevent constructors (PascalCase) to be highlighted as functions - (#match? @function "^[^A-Z]")) - -( - (call_expression - (field_expression (identifier) @function .)) - (#match? @function "^[^A-Z]")) - -( - (broadcast_call_expression - (identifier) @function) - (#match? @function "^[^A-Z]")) - -( - (broadcast_call_expression - (field_expression (identifier) @function .)) - (#match? @function "^[^A-Z]")) - - -; ------------------- -; Functions builtins -; ------------------- - -((identifier) @function.builtin - (#any-of? @function.builtin - "_abstracttype" "_apply_iterate" "_apply_pure" "_call_in_world" "_call_in_world_total" - "_call_latest" "_equiv_typedef" "_expr" "_primitivetype" "_setsuper!" "_structtype" "_typebody!" - "_typevar" "applicable" "apply_type" "arrayref" "arrayset" "arraysize" "const_arrayref" - "donotdelete" "fieldtype" "get_binding_type" "getfield" "ifelse" "invoke" "isa" "isdefined" - "modifyfield!" "nfields" "replacefield!" "set_binding_type!" "setfield!" "sizeof" "svec" - "swapfield!" "throw" "tuple" "typeassert" "typeof")) - -; ----------- -; Parameters -; ----------- +(field_expression + (identifier) + (identifier) @field .) +(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) - -(optional_parameter - . (identifier) @variable.parameter) - -(slurp_parameter - (identifier) @variable.parameter) - +(parameter_list + (optional_parameter . + (identifier) @variable.parameter)) (typed_parameter - parameter: (identifier)? @variable.parameter - type: (_) @type) - + (identifier) @variable.parameter + (identifier) @type) +(type_parameter_list + (identifier) @type) +(typed_parameter + (identifier) @variable.parameter + (parameterized_identifier) @type) (function_expression - . (identifier) @variable.parameter) ; Single parameter arrow functions - -; ----- -; Types -; ----- - -; Definitions -(abstract_definition - name: (identifier) @type.definition) @keyword - -(primitive_definition - name: (identifier) @type.definition) @keyword - -(struct_definition - name: (identifier) @type) - -(struct_definition - . (_) - (identifier) @variable.other.member) - -(struct_definition - . (_) + . (identifier) @variable.parameter) +(spread_parameter) @variable.parameter +(spread_parameter + (identifier) @variable.parameter) +(named_argument + . (identifier) @variable.parameter) +(argument_list (typed_expression - . (identifier) @variable.other.member)) + (identifier) @variable.parameter + (identifier) @type)) +(argument_list + (typed_expression + (identifier) @variable.parameter + (parameterized_identifier) @type)) -(type_clause - [ - (identifier) @type - (field_expression - (identifier) @type .) - ]) +;; Symbol expressions (:my-wanna-be-lisp-keyword) +(quote_expression + (identifier)) @string.special.symbol -; Annotations -(parametrized_type_expression - (_) @type - (curly_expression - (_) @type)) +;; Parsing error! foo (::Type) get's parsed as two quote expressions +(argument_list + (quote_expression + (quote_expression + (identifier) @type))) -(type_parameter_list +(type_argument_list (identifier) @type) +(parameterized_identifier (_)) @type +(argument_list + (typed_expression . (identifier) @variable.parameter)) (typed_expression - (identifier) @type . ) - -(function_definition - return_type: (identifier) @type) - -(short_function_definition - return_type: (identifier) @type) - -(where_clause - (identifier) @type) - -(where_clause - (curly_expression - (_) @type)) - -; --------- -; Builtins -; --------- + (identifier) @type .) +(typed_expression + (parameterized_identifier) @type .) -; This list was generated with: -; -; istype(x) = typeof(x) === DataType || typeof(x) === UnionAll -; get_types(m) = filter(x -> istype(Base.eval(m, x)), names(m)) -; type_names = sort(union(get_types(Core), get_types(Base))) -; -((identifier) @type.builtin - (#any-of? @type.builtin - "AbstractArray" "AbstractChannel" "AbstractChar" "AbstractDict" "AbstractDisplay" - "AbstractFloat" "AbstractIrrational" "AbstractLock" "AbstractMatch" "AbstractMatrix" - "AbstractPattern" "AbstractRange" "AbstractSet" "AbstractSlices" "AbstractString" - "AbstractUnitRange" "AbstractVecOrMat" "AbstractVector" "Any" "ArgumentError" "Array" - "AssertionError" "Atomic" "BigFloat" "BigInt" "BitArray" "BitMatrix" "BitSet" "BitVector" "Bool" - "BoundsError" "By" "CanonicalIndexError" "CapturedException" "CartesianIndex" "CartesianIndices" - "Cchar" "Cdouble" "Cfloat" "Channel" "Char" "Cint" "Cintmax_t" "Clong" "Clonglong" "Cmd" "Colon" - "ColumnSlices" "Complex" "ComplexF16" "ComplexF32" "ComplexF64" "ComposedFunction" - "CompositeException" "ConcurrencyViolationError" "Condition" "Cptrdiff_t" "Cshort" "Csize_t" - "Cssize_t" "Cstring" "Cuchar" "Cuint" "Cuintmax_t" "Culong" "Culonglong" "Cushort" "Cvoid" - "Cwchar_t" "Cwstring" "DataType" "DenseArray" "DenseMatrix" "DenseVecOrMat" "DenseVector" "Dict" - "DimensionMismatch" "Dims" "DivideError" "DomainError" "EOFError" "Enum" "ErrorException" - "Exception" "ExponentialBackOff" "Expr" "Float16" "Float32" "Float64" "Function" "GlobalRef" - "HTML" "IO" "IOBuffer" "IOContext" "IOStream" "IdDict" "IndexCartesian" "IndexLinear" - "IndexStyle" "InexactError" "InitError" "Int" "Int128" "Int16" "Int32" "Int64" "Int8" "Integer" - "InterruptException" "InvalidStateException" "Irrational" "KeyError" "LazyString" "LinRange" - "LineNumberNode" "LinearIndices" "LoadError" "Lt" "MIME" "Matrix" "Method" "MethodError" - "Missing" "MissingException" "Module" "NTuple" "NamedTuple" "Nothing" "Number" "Ordering" - "OrdinalRange" "OutOfMemoryError" "OverflowError" "Pair" "ParseError" "PartialQuickSort" "Perm" - "PermutedDimsArray" "Pipe" "ProcessFailedException" "Ptr" "QuoteNode" "Rational" "RawFD" - "ReadOnlyMemoryError" "Real" "ReentrantLock" "Ref" "Regex" "RegexMatch" "Returns" - "ReverseOrdering" "RoundingMode" "RowSlices" "SegmentationFault" "Set" "Signed" "Slices" "Some" - "SpinLock" "StackFrame" "StackOverflowError" "StackTrace" "Stateful" "StepRange" "StepRangeLen" - "StridedArray" "StridedMatrix" "StridedVecOrMat" "StridedVector" "String" "StringIndexError" - "SubArray" "SubString" "SubstitutionString" "Symbol" "SystemError" "Task" "TaskFailedException" - "Text" "TextDisplay" "Timer" "Tmstruct" "Tuple" "Type" "TypeError" "TypeVar" "UInt" "UInt128" - "UInt16" "UInt32" "UInt64" "UInt8" "UndefInitializer" "UndefKeywordError" "UndefRefError" - "UndefVarError" "Union" "UnionAll" "UnitRange" "Unsigned" "Val" "VecElement" "VecOrMat" "Vector" - "VersionNumber" "WeakKeyDict" "WeakRef")) +(struct_definition + name: (identifier) @type) -((identifier) @variable.builtin - (#any-of? @variable.builtin "begin" "end")) +(number) @number +(range_expression + (identifier) @number + (eq? @number "end")) +(range_expression + (_ + (identifier) @number + (eq? @number "end"))) +(coefficient_expression + (number) + (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 -((identifier) @variable.builtin - (#any-of? @variable.builtin "begin" "end")) +(if_statement + ["if" "end"] @keyword.control.conditional) +(elseif_clause + ["elseif"] @keyword.control.conditional) +(else_clause + ["else"] @keyword.control.conditional) +(ternary_expression + ["?" ":"] @keyword.control.conditional) +(function_definition ["function" "end"] @keyword.function) -; -------- -; Keywords -; -------- +(comment) @comment [ - "global" - "local" + "const" + "return" + "macro" + "struct" + "primitive" + "type" ] @keyword -(compound_statement - [ - "begin" - "end" - ] @keyword) - -(quote_statement - [ - "quote" - "end" - ] @keyword) - -(let_statement - [ - "let" - "end" - ] @keyword) - -(if_statement - [ - "if" - "end" - ] @keyword.control.conditional) - -(elseif_clause - "elseif" @keyword.control.conditional) - -(else_clause - "else" @keyword.control.conditional) - -(if_clause - "if" @keyword.control.conditional) ; `if` clause in comprehensions - -(ternary_expression - [ - "?" - ":" - ] @keyword.control.conditional) +((identifier) @keyword (match? @keyword "global|local")) +(compound_expression + ["begin" "end"] @keyword) (try_statement - [ - "try" - "end" - ] @keyword.control.exception) - + ["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) - + ["for" "end"] @keyword.control.repeat) (while_statement - [ - "while" - "end" - ] @keyword.control.repeat) - + ["while" "end"] @keyword.control.repeat) +(break_statement) @keyword.control.repeat +(continue_statement) @keyword.control.repeat +(for_binding + "in" @keyword.control.repeat) (for_clause "for" @keyword.control.repeat) - -[ - (break_statement) - (continue_statement) -] @keyword.control.repeat - -(module_definition - [ - "module" - "baremodule" - "end" - ] @keyword.control.import) - -(import_statement - [ - "import" - "using" - ] @keyword.control.import) - -(import_alias - "as" @keyword.control.import) - -(export_statement - "export" @keyword.control.import) - -(selected_import - ":" @punctuation.delimiter) - -(struct_definition - [ - "struct" - "end" - ] @keyword) - -(macro_definition - [ - "macro" - "end" - ] @keyword) - -(function_definition - [ - "function" - "end" - ] @keyword.function) - (do_clause - [ - "do" - "end" - ] @keyword.function) - -(return_statement - "return" @keyword.control.return) - -[ - "const" - "mutable" -] @keyword.storage.modifier - -; --------- -; Operators -; --------- - -[ - (operator) - "=" - "∈" -] @operator - -(adjoint_expression - "'" @operator) - -(range_expression - ":" @operator) - -((operator) @keyword.operator - (#any-of? @keyword.operator "in" "isa")) - -(for_binding - "in" @keyword.operator) - -(where_clause - "where" @keyword.operator) + ["do" "end"] @keyword) -(where_expression - "where" @keyword.operator) - -(binary_expression - (_) - (operator) @operator - (identifier) @function - (#any-of? @operator "|>" ".|>")) - -; ------------ -; Punctuations -; ------------ - -[ - "." - "," - ";" - "::" - "->" -] @punctuation.delimiter - -"..." @punctuation.special +(export_statement + ["export"] @keyword.control.import) [ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket - -; --------- -; Literals -; --------- - -(boolean_literal) @constant.builtin.boolean + "using" + "module" + "import" +] @keyword.control.import -(integer_literal) @constant.numeric.integer +((identifier) @keyword.control.import (#eq? @keyword.control.import "baremodule")) -(float_literal) @constant.numeric.float +(((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")) -( - ((identifier) @constant.numeric.float) - (#match? @constant.numeric.float "^((Inf|NaN)(16|32|64)?)$")) -( - ((identifier) @constant.builtin) - (#match? @constant.builtin "^(nothing|missing|undef)$")) +["::" ":" "." "," "..." "!"] @punctuation.delimiter +["[" "]" "(" ")" "{" "}"] @punctuation.bracket -(character_literal) @constant.character +["="] @operator -(escape_sequence) @constant.character.escape - -(string_literal) @string - -(prefixed_string_literal - prefix: (identifier) @function.macro) @string - -(command_literal) @string - -(prefixed_command_literal - prefix: (identifier) @function.macro) @string - -; --------- -; Comments -; --------- - -[ - (line_comment) - (block_comment) -] @comment +(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_]*$")) |