feat(julia): update parser and queries

This commit is contained in:
Christian Clason 2024-11-11 08:39:00 +01:00 committed by Christian Clason
parent a069bb62a8
commit d105f2cb7b
4 changed files with 157 additions and 177 deletions

View file

@ -31,7 +31,7 @@ jobs:
- name: Update parsers
env:
SKIP_LOCKFILE_UPDATE_FOR_LANGS: "gnuplot,julia,unison"
SKIP_LOCKFILE_UPDATE_FOR_LANGS: "gnuplot,unison"
run: |
cp lockfile.json /tmp/old_lockfile.json
nvim -l scripts/write-lockfile.lua

View file

@ -387,7 +387,7 @@
"revision": "ddd075f1939aed8147b7aa67f042eda3fce22790"
},
"julia": {
"revision": "19f62656dc7f2ff3756a8ef3dcf9ab1c01a9eb58"
"revision": "3f51e8e4d9b0c7b10d663d72064c45a883c2c998"
},
"just": {
"revision": "1014d2fd6396856c312054d6c30df4d78b62966c"

View file

@ -1,9 +1,10 @@
; Identifiers
(identifier) @variable
; ;; 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
(field_expression
(identifier) @variable.member .)
; Symbols
(quote_expression
":" @string.special.symbol
[
@ -11,10 +12,7 @@
(operator)
] @string.special.symbol)
(field_expression
(identifier) @variable.member .)
; calls
; Function calls
(call_expression
(identifier) @function.call)
@ -35,113 +33,66 @@
(identifier) @function.call
(#any-of? @_pipe "|>" ".|>"))
; Macros
(macro_identifier) @function.macro
(macro_identifier
(identifier) @function.macro) ; for any one using the variable highlight
(macro_definition
(signature
(call_expression
.
(identifier) @function.macro)))
; Builtins
; Built-in functions
; filter(name -> Base.eval(Core, name) isa Core.Builtin, names(Core))
((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"))
"applicable" "fieldtype" "getfield" "getglobal" "invoke" "isa" "isdefined" "modifyfield!"
"modifyglobal!" "nfields" "replacefield!" "replaceglobal!" "setfield!" "setfieldonce!"
"setglobal!" "setglobalonce!" "swapfield!" "swapglobal!" "throw" "tuple" "typeassert" "typeof"))
; Types
; Definitions
(abstract_definition
name: (identifier) @type.definition) @keyword
; Type definitions
(type_head
(_) @type.definition)
(primitive_definition
name: (identifier) @type.definition) @keyword
(struct_definition
name: (identifier) @type)
(type_clause
; Type annotations
(parametrized_type_expression
[
(identifier) @type
(field_expression
(identifier) @type .)
])
; Annotations
(parametrized_type_expression
(_) @type
]
(curly_expression
(_) @type))
(type_parameter_list
(identifier) @type)
(typed_expression
(identifier) @type .)
(unary_typed_expression
(identifier) @type .)
(where_clause
(identifier) @type)
(where_expression
(_) @type .)
(where_clause
(curly_expression
(_) @type))
(binary_expression
(_) @type
(operator) @operator
(_) @type
(#any-of? @operator "<:" ">:"))
; Builtins
; 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)))
;
; Built-in types
; filter(name -> typeof(Base.eval(Core, name)) in [DataType, UnionAll], names(Core))
((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"))
((identifier) @variable.builtin
(#any-of? @variable.builtin "begin" "end")
(#has-ancestor? @variable.builtin index_expression))
((identifier) @variable.builtin
(#any-of? @variable.builtin "begin" "end")
(#has-ancestor? @variable.builtin range_expression))
"AbstractArray" "AbstractChar" "AbstractFloat" "AbstractString" "Any" "ArgumentError" "Array"
"AssertionError" "Bool" "BoundsError" "Char" "ConcurrencyViolationError" "Cvoid" "DataType"
"DenseArray" "DivideError" "DomainError" "ErrorException" "Exception" "Expr" "Float16" "Float32"
"Float64" "Function" "GlobalRef" "IO" "InexactError" "InitError" "Int" "Int128" "Int16" "Int32"
"Int64" "Int8" "Integer" "InterruptException" "LineNumberNode" "LoadError" "Method"
"MethodError" "Module" "NTuple" "NamedTuple" "Nothing" "Number" "OutOfMemoryError"
"OverflowError" "Pair" "Ptr" "QuoteNode" "ReadOnlyMemoryError" "Real" "Ref" "SegmentationFault"
"Signed" "StackOverflowError" "String" "Symbol" "Task" "Tuple" "Type" "TypeError" "TypeVar"
"UInt" "UInt128" "UInt16" "UInt32" "UInt64" "UInt8" "UndefInitializer" "UndefKeywordError"
"UndefRefError" "UndefVarError" "Union" "UnionAll" "Unsigned" "VecElement" "WeakRef"))
; Keywords
[
@ -179,9 +130,6 @@
(else_clause
"else" @keyword.conditional)
(if_clause
"if" @keyword.conditional) ; `if` clause in comprehensions
(ternary_expression
[
"?"
@ -194,68 +142,43 @@
"end"
] @keyword.exception)
(finally_clause
"finally" @keyword.exception)
(catch_clause
"catch" @keyword.exception)
(finally_clause
"finally" @keyword.exception)
(for_statement
[
"for"
"end"
] @keyword.repeat)
(for_binding
"outer" @keyword.repeat)
; comprehensions
(for_clause
"for" @keyword.repeat)
(if_clause
"if" @keyword.conditional)
(while_statement
[
"while"
"end"
] @keyword.repeat)
(for_clause
"for" @keyword.repeat)
(for_binding
"outer" @keyword.repeat)
[
(break_statement)
(continue_statement)
] @keyword.repeat
(module_definition
[
"module"
"baremodule"
"end"
] @keyword.import)
(import_statement
[
"import"
"using"
] @keyword.import)
(import_alias
"as" @keyword.import)
(export_statement
"export" @keyword.import)
(selected_import
":" @punctuation.delimiter)
(struct_definition
[
"struct"
"end"
] @keyword.type)
(macro_definition
[
"macro"
"end"
] @keyword)
[
"const"
"mutable"
] @keyword.modifier
(function_definition
[
@ -269,20 +192,63 @@
"end"
] @keyword.function)
(macro_definition
[
"macro"
"end"
] @keyword)
(return_statement
"return" @keyword.return)
[
"const"
"mutable"
] @keyword.modifier
(module_definition
[
"module"
"baremodule"
"end"
] @keyword.import)
(export_statement
"export" @keyword.import)
(public_statement
"public" @keyword.import)
(import_statement
"import" @keyword.import)
(using_statement
"using" @keyword.import)
(import_alias
"as" @keyword.import)
(selected_import
":" @punctuation.delimiter)
(struct_definition
[
"mutable"
"struct"
"end"
] @keyword.type)
(abstract_definition
[
"abstract"
"type"
"end"
] @keyword.type)
(primitive_definition
[
"primitive"
"type"
"end"
] @keyword.type)
; Operators & Punctuation
[
"="
"∈"
(operator)
] @operator
(operator) @operator
(adjoint_expression
"'" @operator)
@ -290,28 +256,20 @@
(range_expression
":" @operator)
((operator) @keyword.operator
(#any-of? @keyword.operator "in" "isa"))
(arrow_function_expression
"->" @operator)
(for_binding
"in" @keyword.operator)
(where_clause
"where" @keyword.operator)
(where_expression
"where" @keyword.operator)
[
"."
"..."
] @punctuation.special
[
","
"."
";"
"::"
"->"
] @punctuation.delimiter
"..." @punctuation.special
[
"("
")"
@ -321,6 +279,21 @@
"}"
] @punctuation.bracket
; Keyword operators
((operator) @keyword.operator
(#any-of? @keyword.operator "in" "isa"))
(where_expression
"where" @keyword.operator)
; Built-in constants
((identifier) @constant.builtin
(#any-of? @constant.builtin "nothing" "missing"))
((identifier) @variable.builtin
(#any-of? @variable.builtin "begin" "end")
(#has-ancestor? @variable.builtin index_expression))
; Literals
(boolean_literal) @boolean
@ -331,9 +304,6 @@
((identifier) @number.float
(#any-of? @number.float "NaN" "NaN16" "NaN32" "Inf" "Inf16" "Inf32"))
((identifier) @constant.builtin
(#any-of? @constant.builtin "nothing" "missing"))
(character_literal) @character
(escape_sequence) @string.escape
@ -348,15 +318,16 @@
(prefixed_command_literal
prefix: (identifier) @function.macro) @string.special
((string_literal) @string.documentation @spell
((string_literal) @string.documentation
.
[
(module_definition)
(abstract_definition)
(struct_definition)
(function_definition)
(assignment)
(const_statement)
(function_definition)
(macro_definition)
(module_definition)
(struct_definition)
])
[

View file

@ -1,3 +1,6 @@
; References
(identifier) @local.reference
; Variables
(assignment
(identifier) @local.definition.var)
@ -23,23 +26,31 @@
(identifier) @local.definition.var))
; Types
(struct_definition
name: (identifier) @local.definition.type)
(abstract_definition
name: (identifier) @local.definition.type)
(abstract_definition
name: (identifier) @local.definition.type)
(type_parameter_list
(module_definition
(identifier) @local.definition.type)
(struct_definition
(identifier) @local.definition.type)
(type_head
(identifier) @local.definition.type)
(type_head
(binary_expression
.
(identifier) @local.definition.type))
; Module imports
(import_statement
(identifier) @local.definition.import)
; Function/macro definitions
(using_statement
(identifier) @local.definition.import)
(selected_import
(identifier) @local.definition.import)
; Scopes
(function_definition
(signature
(call_expression
@ -52,15 +63,13 @@
.
(identifier) @local.definition.function))) @local.scope
(identifier) @local.reference
[
(quote_statement)
(let_statement)
(for_statement)
(while_statement)
(try_statement)
(catch_clause)
(finally_clause)
(let_statement)
(quote_statement)
(do_clause)
] @local.scope