Update tree-sitter-julia (#10031)

Update julia parser to latest version, along with:
- updating the queries,
- pulling changes from `nvim-treesitter`’s queries (as the maintainters
  of the parser update the queries there),
- reversing the queries’ order to be compatible with upstream.
pull/10793/head
Iorvethe 6 months ago committed by Blaž Hrastnik
parent 0364f7c879
commit 951b454a33

@ -1115,7 +1115,7 @@ indent = { tab-width = 4, unit = " " }
[[grammar]] [[grammar]]
name = "julia" name = "julia"
source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "8fb38abff74652c4faddbf04d2d5bbbc6b4bae25" } source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "e84f10db8eeb8b9807786bfc658808edaa1b4fa2" }
[[language]] [[language]]
name = "java" name = "java"

@ -3,9 +3,12 @@
(struct_definition) (struct_definition)
(macro_definition) (macro_definition)
(function_definition) (function_definition)
(compound_expression) ; begin blocks
(let_statement)
(if_statement) (if_statement)
(try_statement)
(for_statement) (for_statement)
(while_statement) (while_statement)
(let_statement)
(quote_statement)
(do_clause)
(compound_statement) ; begin block
] @fold ] @fold

@ -1,38 +1,47 @@
; ---------- ; ------------
; Primitives ; Variables identifiers
; ---------- ; ------------
[ (identifier) @variable
(line_comment)
(block_comment)
] @comment
; Remaining identifiers that start with capital letters should be types (PascalCase)
( (
((identifier) @constant.builtin) (identifier) @type
(#match? @constant.builtin "^(nothing|missing|undef)$")) (match? @type "^[A-Z]"))
[ ; SCREAMING_SNAKE_CASE
(true) (
(false) (identifier) @constant
] @constant.builtin.boolean (match? @constant "^[A-Z][A-Z0-9_]*$"))
(integer_literal) @constant.numeric.integer (const_statement
(float_literal) @constant.numeric.float (assignment
. (identifier) @constant))
( ; Field expressions are either module content or struct fields.
((identifier) @constant.numeric.float) ; Module types and constants should already be captured, so this
(#match? @constant.numeric.float "^((Inf|NaN)(16|32|64)?)$")) ; assumes the remaining identifiers to be struct fields.
(field_expression
(_)
(identifier) @variable.other.member)
(character_literal) @constant.character (quote_expression
(escape_sequence) @constant.character.escape ":" @string.special.symbol
[
(identifier)
(operator)
] @string.special.symbol)
(string_literal) @string ; ------
; Macros
; ------
(prefixed_string_literal (macro_definition
prefix: (identifier) @function.macro) @string name: (identifier) @function.macro)
(quote_expression (macro_identifier
(identifier) @string.special.symbol) "@" @function.macro
(identifier) @function.macro)
; ------------------- ; -------------------
; Modules and Imports ; Modules and Imports
@ -50,49 +59,6 @@
(scoped_identifier (scoped_identifier
(identifier) @namespace) (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_type_parameter
(identifier) @type)
(subtype_clause
(identifier) @type)
(typed_expression
(identifier) @type . )
(parameterized_identifier
(identifier) @type)
(type_argument_list
(identifier) @type)
(where_clause
(identifier) @type)
; ------------------- ; -------------------
; Function definition ; Function definition
; ------------------- ; -------------------
@ -119,22 +85,6 @@
; prevent constructors (PascalCase) to be highlighted as functions ; prevent constructors (PascalCase) to be highlighted as functions
(#match? @function "^[^A-Z]")) (#match? @function "^[^A-Z]"))
(parameter_list
(identifier) @variable.parameter)
(typed_parameter
(identifier) @variable.parameter
(identifier)? @type)
(optional_parameter
. (identifier) @variable.parameter)
(slurp_parameter
(identifier) @variable.parameter)
(function_expression
. (identifier) @variable.parameter)
; --------------- ; ---------------
; Functions calls ; Functions calls
; --------------- ; ---------------
@ -146,13 +96,13 @@
(#match? @function "^[^A-Z]")) (#match? @function "^[^A-Z]"))
( (
(broadcast_call_expression (call_expression
(identifier) @function) (field_expression (identifier) @function .))
(#match? @function "^[^A-Z]")) (#match? @function "^[^A-Z]"))
( (
(call_expression (broadcast_call_expression
(field_expression (identifier) @function .)) (identifier) @function)
(#match? @function "^[^A-Z]")) (#match? @function "^[^A-Z]"))
( (
@ -160,78 +110,279 @@
(field_expression (identifier) @function .)) (field_expression (identifier) @function .))
(#match? @function "^[^A-Z]")) (#match? @function "^[^A-Z]"))
; ------
; Macros
; ------
(macro_definition ; -------------------
name: (identifier) @function.macro) ; 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
; -----------
(parameter_list
(identifier) @variable.parameter)
(optional_parameter
. (identifier) @variable.parameter)
(slurp_parameter
(identifier) @variable.parameter)
(typed_parameter
parameter: (identifier)? @variable.parameter
type: (_) @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
. (_)
(typed_expression
. (identifier) @variable.other.member))
(type_clause
[
(identifier) @type
(field_expression
(identifier) @type .)
])
; Annotations
(parametrized_type_expression
(_) @type
(curly_expression
(_) @type))
(type_parameter_list
(identifier) @type)
(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
; ---------
; 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"))
((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))
(macro_identifier
"@" @function.macro
(identifier) @function.macro)
; -------- ; --------
; Keywords ; Keywords
; -------- ; --------
(function_definition [
["function" "end"] @keyword.function) "global"
"local"
] @keyword
(compound_statement
[
"begin"
"end"
] @keyword)
(quote_statement
[
"quote"
"end"
] @keyword)
(let_statement
[
"let"
"end"
] @keyword)
(if_statement (if_statement
["if" "end"] @keyword.control.conditional) [
"if"
"end"
] @keyword.control.conditional)
(elseif_clause (elseif_clause
["elseif"] @keyword.control.conditional) "elseif" @keyword.control.conditional)
(else_clause (else_clause
["else"] @keyword.control.conditional) "else" @keyword.control.conditional)
(ternary_expression
["?" ":"] @keyword.control.conditional)
(for_statement (if_clause
["for" "end"] @keyword.control.repeat) "if" @keyword.control.conditional) ; `if` clause in comprehensions
(while_statement
["while" "end"] @keyword.control.repeat) (ternary_expression
(break_statement) @keyword.control.repeat [
(continue_statement) @keyword.control.repeat "?"
(for_binding ":"
"in" @keyword.control.repeat) ] @keyword.control.conditional)
(for_clause
"for" @keyword.control.repeat)
(try_statement (try_statement
["try" "end" ] @keyword.control.exception) [
"try"
"end"
] @keyword.control.exception)
(finally_clause (finally_clause
"finally" @keyword.control.exception) "finally" @keyword.control.exception)
(catch_clause (catch_clause
"catch" @keyword.control.exception) "catch" @keyword.control.exception)
(for_statement
[
"for"
"end"
] @keyword.control.repeat)
(while_statement
[
"while"
"end"
] @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
[ [
"export"
"import" "import"
"using" "using"
] @keyword.control.import ] @keyword.control.import)
(import_alias
"as" @keyword.control.import)
(export_statement
"export" @keyword.control.import)
(selected_import
":" @punctuation.delimiter)
(struct_definition
[ [
"abstract" "struct"
"baremodule"
"begin"
"const"
"do"
"end" "end"
"let" ] @keyword)
(macro_definition
[
"macro" "macro"
"module" "end"
"mutable" ] @keyword)
"primitive"
"quote" (function_definition
"return" [
"struct" "function"
"type" "end"
"where" ] @keyword.function)
] @keyword
(do_clause
[
"do"
"end"
] @keyword.function)
(return_statement
"return" @keyword.control.return)
; TODO: fix this [
((identifier) @keyword (#match? @keyword "global|local")) "const"
"mutable"
] @keyword.storage.modifier
; --------- ; ---------
; Operators ; Operators
@ -239,14 +390,34 @@
[ [
(operator) (operator)
"::" "="
"<:" "∈"
":"
"=>"
"..."
"$"
] @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)
(where_expression
"where" @keyword.operator)
(binary_expression
(_)
(operator) @operator
(identifier) @function
(#any-of? @operator "|>" ".|>"))
; ------------ ; ------------
; Punctuations ; Punctuations
; ------------ ; ------------
@ -255,40 +426,58 @@
"." "."
"," ","
";" ";"
"::"
"->"
] @punctuation.delimiter ] @punctuation.delimiter
"..." @punctuation.special
[ [
"["
"]"
"(" "("
")" ")"
"["
"]"
"{" "{"
"}" "}"
] @punctuation.bracket ] @punctuation.bracket
; --------------------- ; ---------
; Remaining identifiers ; Literals
; --------------------- ; ---------
(const_statement (boolean_literal) @constant.builtin.boolean
(variable_declaration
. (identifier) @constant)) (integer_literal) @constant.numeric.integer
(float_literal) @constant.numeric.float
; SCREAMING_SNAKE_CASE
( (
(identifier) @constant ((identifier) @constant.numeric.float)
(#match? @constant "^[A-Z][A-Z0-9_]*$")) (#match? @constant.numeric.float "^((Inf|NaN)(16|32|64)?)$"))
; remaining identifiers that start with capital letters should be types (PascalCase)
( (
(identifier) @type ((identifier) @constant.builtin)
(#match? @type "^[A-Z]")) (#match? @constant.builtin "^(nothing|missing|undef)$"))
; Field expressions are either module content or struct fields. (character_literal) @constant.character
; Module types and constants should already be captured, so this
; assumes the remaining identifiers to be struct fields.
(field_expression
(_)
(identifier) @variable.other.member)
(identifier) @variable (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

@ -2,15 +2,39 @@
(struct_definition) (struct_definition)
(macro_definition) (macro_definition)
(function_definition) (function_definition)
(compound_expression) (compound_statement)
(let_statement)
(if_statement) (if_statement)
(try_statement)
(for_statement) (for_statement)
(while_statement) (while_statement)
(let_statement)
(quote_statement)
(do_clause) (do_clause)
(parameter_list) (assignment)
(for_binding)
(call_expression)
(parenthesized_expression)
(tuple_expression)
(comprehension_expression)
(matrix_expression)
(vector_expression)
] @indent ] @indent
[ [
"end" "end"
")"
"]"
"}"
] @outdent ] @outdent
(argument_list
. (_) @anchor
(#set! "scope" "tail")) @align
(parameter_list
. (_) @anchor
(#set! "scope" "tail")) @align
(curly_expression
. (_) @anchor
(#set! "scope" "tail")) @align

@ -9,7 +9,8 @@
(primitive_definition) (primitive_definition)
(abstract_definition) (abstract_definition)
(struct_definition) (struct_definition)
(assignment_expression) (short_function_definition)
(assignment)
(const_statement) (const_statement)
]) ])
(#set! injection.language "markdown")) (#set! injection.language "markdown"))
@ -21,10 +22,17 @@
] @injection.content ] @injection.content
(#set! injection.language "comment")) (#set! injection.language "comment"))
(
[
(command_literal)
(prefixed_command_literal)
] @injection.content
(#set! injection.language "sh"))
( (
(prefixed_string_literal (prefixed_string_literal
prefix: (identifier) @function.macro) @injection.content prefix: (identifier) @function.macro) @injection.content
(#eq? @function.macro "re") (#eq? @function.macro "r")
(#set! injection.language "regex")) (#set! injection.language "regex"))
( (

@ -2,43 +2,100 @@
; Definitions ; Definitions
; ----------- ; -----------
; Imports ; Variables
(import_statement (assignment
(identifier) @local.definition) (identifier) @local.definition)
(assignment
(tuple_expression
(identifier) @local.definition))
; Constants ; Constants
(const_statement (const_statement
(variable_declaration (assignment
. (identifier) @local.definition)) . (identifier) @local.definition))
; let/const bindings
(let_binding
(identifier) @local.definition)
(let_binding
(tuple_expression
(identifier) @local.definition))
; For bindings
(for_binding
(identifier) @local.definition)
(for_binding
(tuple_expression
(identifier) @local.definition))
; Types
(struct_definition
name: (identifier) @local.definition)
(abstract_definition
name: (identifier) @local.definition)
(abstract_definition
name: (identifier) @local.definition)
(type_parameter_list
(identifier) @local.definition)
; Module imports
(import_statement
(identifier) @local.definition)
; Parameters ; Parameters
(parameter_list (parameter_list
(identifier) @local.definition) (identifier) @local.definition)
(typed_parameter (optional_parameter
. (identifier) @local.definition) .
(optional_parameter .
(identifier) @local.definition) (identifier) @local.definition)
(slurp_parameter (slurp_parameter
(identifier) @local.definition) (identifier) @local.definition)
(typed_parameter
parameter: (identifier) @local.definition
(_))
; Single parameter arrow function
(function_expression (function_expression
. (identifier) @local.definition) .
(identifier) @local.definition)
; ------ ; Function/macro definitions
; Scopes (function_definition
; ------ name: (identifier) @local.definition) @local.scope
[ (short_function_definition
(function_definition) name: (identifier) @local.definition) @local.scope
(short_function_definition)
(macro_definition) (macro_definition
] @local.scope name: (identifier) @local.definition) @local.scope
; ---------- ; ----------
; References ; References
; ---------- ; ----------
(identifier) @local.reference (identifier) @local.reference
; ------
; Scopes
; ------
[
(for_statement)
(while_statement)
(try_statement)
(catch_clause)
(finally_clause)
(let_statement)
(quote_statement)
(do_clause)
] @local.scope

Loading…
Cancel
Save