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 - name: Update parsers
env: env:
SKIP_LOCKFILE_UPDATE_FOR_LANGS: "gnuplot,julia,unison" SKIP_LOCKFILE_UPDATE_FOR_LANGS: "gnuplot,unison"
run: | run: |
cp lockfile.json /tmp/old_lockfile.json cp lockfile.json /tmp/old_lockfile.json
nvim -l scripts/write-lockfile.lua nvim -l scripts/write-lockfile.lua

View file

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

View file

@ -1,9 +1,10 @@
; Identifiers ; Identifiers
(identifier) @variable (identifier) @variable
; ;; If you want type highlighting based on Julia naming conventions (this might collide with mathematical notation) (field_expression
; ((identifier) @type (identifier) @variable.member .)
; (match? @type "^[A-Z][^_]")) ; exception: Highlight `A_foo` sort of identifiers as variables
; Symbols
(quote_expression (quote_expression
":" @string.special.symbol ":" @string.special.symbol
[ [
@ -11,10 +12,7 @@
(operator) (operator)
] @string.special.symbol) ] @string.special.symbol)
(field_expression ; Function calls
(identifier) @variable.member .)
; calls
(call_expression (call_expression
(identifier) @function.call) (identifier) @function.call)
@ -35,113 +33,66 @@
(identifier) @function.call (identifier) @function.call
(#any-of? @_pipe "|>" ".|>")) (#any-of? @_pipe "|>" ".|>"))
; Macros
(macro_identifier) @function.macro (macro_identifier) @function.macro
(macro_identifier
(identifier) @function.macro) ; for any one using the variable highlight
(macro_definition (macro_definition
(signature (signature
(call_expression (call_expression
. .
(identifier) @function.macro))) (identifier) @function.macro)))
; Builtins ; Built-in functions
; filter(name -> Base.eval(Core, name) isa Core.Builtin, names(Core))
((identifier) @function.builtin ((identifier) @function.builtin
(#any-of? @function.builtin (#any-of? @function.builtin
"_abstracttype" "_apply_iterate" "_apply_pure" "_call_in_world" "_call_in_world_total" "applicable" "fieldtype" "getfield" "getglobal" "invoke" "isa" "isdefined" "modifyfield!"
"_call_latest" "_equiv_typedef" "_expr" "_primitivetype" "_setsuper!" "_structtype" "_typebody!" "modifyglobal!" "nfields" "replacefield!" "replaceglobal!" "setfield!" "setfieldonce!"
"_typevar" "applicable" "apply_type" "arrayref" "arrayset" "arraysize" "const_arrayref" "setglobal!" "setglobalonce!" "swapfield!" "swapglobal!" "throw" "tuple" "typeassert" "typeof"))
"donotdelete" "fieldtype" "get_binding_type" "getfield" "ifelse" "invoke" "isa" "isdefined"
"modifyfield!" "nfields" "replacefield!" "set_binding_type!" "setfield!" "sizeof" "svec"
"swapfield!" "throw" "tuple" "typeassert" "typeof"))
; Types ; Type definitions
; Definitions (type_head
(abstract_definition (_) @type.definition)
name: (identifier) @type.definition) @keyword
(primitive_definition ; Type annotations
name: (identifier) @type.definition) @keyword (parametrized_type_expression
(struct_definition
name: (identifier) @type)
(type_clause
[ [
(identifier) @type (identifier) @type
(field_expression (field_expression
(identifier) @type .) (identifier) @type .)
]) ]
; Annotations
(parametrized_type_expression
(_) @type
(curly_expression (curly_expression
(_) @type)) (_) @type))
(type_parameter_list
(identifier) @type)
(typed_expression (typed_expression
(identifier) @type .) (identifier) @type .)
(unary_typed_expression (unary_typed_expression
(identifier) @type .) (identifier) @type .)
(where_clause (where_expression
(identifier) @type) (_) @type .)
(where_clause (binary_expression
(curly_expression (_) @type
(_) @type)) (operator) @operator
(_) @type
(#any-of? @operator "<:" ">:"))
; Builtins ; Built-in types
; This list was generated with: ; filter(name -> typeof(Base.eval(Core, name)) in [DataType, UnionAll], names(Core))
;
; 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 ((identifier) @type.builtin
(#any-of? @type.builtin (#any-of? @type.builtin
"AbstractArray" "AbstractChannel" "AbstractChar" "AbstractDict" "AbstractDisplay" "AbstractArray" "AbstractChar" "AbstractFloat" "AbstractString" "Any" "ArgumentError" "Array"
"AbstractFloat" "AbstractIrrational" "AbstractLock" "AbstractMatch" "AbstractMatrix" "AssertionError" "Bool" "BoundsError" "Char" "ConcurrencyViolationError" "Cvoid" "DataType"
"AbstractPattern" "AbstractRange" "AbstractSet" "AbstractSlices" "AbstractString" "DenseArray" "DivideError" "DomainError" "ErrorException" "Exception" "Expr" "Float16" "Float32"
"AbstractUnitRange" "AbstractVecOrMat" "AbstractVector" "Any" "ArgumentError" "Array" "Float64" "Function" "GlobalRef" "IO" "InexactError" "InitError" "Int" "Int128" "Int16" "Int32"
"AssertionError" "Atomic" "BigFloat" "BigInt" "BitArray" "BitMatrix" "BitSet" "BitVector" "Bool" "Int64" "Int8" "Integer" "InterruptException" "LineNumberNode" "LoadError" "Method"
"BoundsError" "By" "CanonicalIndexError" "CapturedException" "CartesianIndex" "CartesianIndices" "MethodError" "Module" "NTuple" "NamedTuple" "Nothing" "Number" "OutOfMemoryError"
"Cchar" "Cdouble" "Cfloat" "Channel" "Char" "Cint" "Cintmax_t" "Clong" "Clonglong" "Cmd" "Colon" "OverflowError" "Pair" "Ptr" "QuoteNode" "ReadOnlyMemoryError" "Real" "Ref" "SegmentationFault"
"ColumnSlices" "Complex" "ComplexF16" "ComplexF32" "ComplexF64" "ComposedFunction" "Signed" "StackOverflowError" "String" "Symbol" "Task" "Tuple" "Type" "TypeError" "TypeVar"
"CompositeException" "ConcurrencyViolationError" "Condition" "Cptrdiff_t" "Cshort" "Csize_t" "UInt" "UInt128" "UInt16" "UInt32" "UInt64" "UInt8" "UndefInitializer" "UndefKeywordError"
"Cssize_t" "Cstring" "Cuchar" "Cuint" "Cuintmax_t" "Culong" "Culonglong" "Cushort" "Cvoid" "UndefRefError" "UndefVarError" "Union" "UnionAll" "Unsigned" "VecElement" "WeakRef"))
"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))
; Keywords ; Keywords
[ [
@ -179,9 +130,6 @@
(else_clause (else_clause
"else" @keyword.conditional) "else" @keyword.conditional)
(if_clause
"if" @keyword.conditional) ; `if` clause in comprehensions
(ternary_expression (ternary_expression
[ [
"?" "?"
@ -194,68 +142,43 @@
"end" "end"
] @keyword.exception) ] @keyword.exception)
(finally_clause
"finally" @keyword.exception)
(catch_clause (catch_clause
"catch" @keyword.exception) "catch" @keyword.exception)
(finally_clause
"finally" @keyword.exception)
(for_statement (for_statement
[ [
"for" "for"
"end" "end"
] @keyword.repeat) ] @keyword.repeat)
(for_binding
"outer" @keyword.repeat)
; comprehensions
(for_clause
"for" @keyword.repeat)
(if_clause
"if" @keyword.conditional)
(while_statement (while_statement
[ [
"while" "while"
"end" "end"
] @keyword.repeat) ] @keyword.repeat)
(for_clause
"for" @keyword.repeat)
(for_binding
"outer" @keyword.repeat)
[ [
(break_statement) (break_statement)
(continue_statement) (continue_statement)
] @keyword.repeat ] @keyword.repeat
(module_definition [
[ "const"
"module" "mutable"
"baremodule" ] @keyword.modifier
"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)
(function_definition (function_definition
[ [
@ -269,20 +192,63 @@
"end" "end"
] @keyword.function) ] @keyword.function)
(macro_definition
[
"macro"
"end"
] @keyword)
(return_statement (return_statement
"return" @keyword.return) "return" @keyword.return)
[ (module_definition
"const" [
"mutable" "module"
] @keyword.modifier "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 ; Operators & Punctuation
[ (operator) @operator
"="
"∈"
(operator)
] @operator
(adjoint_expression (adjoint_expression
"'" @operator) "'" @operator)
@ -290,28 +256,20 @@
(range_expression (range_expression
":" @operator) ":" @operator)
((operator) @keyword.operator (arrow_function_expression
(#any-of? @keyword.operator "in" "isa")) "->" @operator)
(for_binding [
"in" @keyword.operator) "."
"..."
(where_clause ] @punctuation.special
"where" @keyword.operator)
(where_expression
"where" @keyword.operator)
[ [
"," ","
"."
";" ";"
"::" "::"
"->"
] @punctuation.delimiter ] @punctuation.delimiter
"..." @punctuation.special
[ [
"(" "("
")" ")"
@ -321,6 +279,21 @@
"}" "}"
] @punctuation.bracket ] @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 ; Literals
(boolean_literal) @boolean (boolean_literal) @boolean
@ -331,9 +304,6 @@
((identifier) @number.float ((identifier) @number.float
(#any-of? @number.float "NaN" "NaN16" "NaN32" "Inf" "Inf16" "Inf32")) (#any-of? @number.float "NaN" "NaN16" "NaN32" "Inf" "Inf16" "Inf32"))
((identifier) @constant.builtin
(#any-of? @constant.builtin "nothing" "missing"))
(character_literal) @character (character_literal) @character
(escape_sequence) @string.escape (escape_sequence) @string.escape
@ -348,15 +318,16 @@
(prefixed_command_literal (prefixed_command_literal
prefix: (identifier) @function.macro) @string.special prefix: (identifier) @function.macro) @string.special
((string_literal) @string.documentation @spell ((string_literal) @string.documentation
. .
[ [
(module_definition)
(abstract_definition) (abstract_definition)
(struct_definition)
(function_definition)
(assignment) (assignment)
(const_statement) (const_statement)
(function_definition)
(macro_definition)
(module_definition)
(struct_definition)
]) ])
[ [

View file

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