|
|
@ -1,125 +1,213 @@
|
|
|
|
["when" "and" "or" "not in" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
|
|
|
|
; The following code originates mostly from
|
|
|
|
|
|
|
|
; https://github.com/elixir-lang/tree-sitter-elixir, with minor edits to
|
|
|
|
|
|
|
|
; align the captures with helix. The following should be considered
|
|
|
|
|
|
|
|
; Copyright 2021 The Elixir Team
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
; Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
; you may not use this file except in compliance with the License.
|
|
|
|
|
|
|
|
; You may obtain a copy of the License at
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
; https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
; Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
|
|
; distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
|
|
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
|
|
; See the License for the specific language governing permissions and
|
|
|
|
|
|
|
|
; limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Reserved keywords
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
["when" "and" "or" "not" "in" "not in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Operators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * doc string
|
|
|
|
|
|
|
|
(unary_operator
|
|
|
|
|
|
|
|
operator: "@" @comment.block.documentation
|
|
|
|
|
|
|
|
operand: (call
|
|
|
|
|
|
|
|
target: (identifier) @comment.block.documentation.__attribute__
|
|
|
|
|
|
|
|
(arguments
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
(string) @comment.block.documentation
|
|
|
|
|
|
|
|
(charlist) @comment.block.documentation
|
|
|
|
|
|
|
|
(sigil
|
|
|
|
|
|
|
|
quoted_start: _ @comment.block.documentation
|
|
|
|
|
|
|
|
quoted_end: _ @comment.block.documentation) @comment.block.documentation
|
|
|
|
|
|
|
|
(boolean) @comment.block.documentation
|
|
|
|
|
|
|
|
]))
|
|
|
|
|
|
|
|
(#match? @comment.block.documentation.__attribute__ "^(moduledoc|typedoc|doc)$"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * module attribute
|
|
|
|
|
|
|
|
(unary_operator
|
|
|
|
|
|
|
|
operator: "@" @variable.property
|
|
|
|
|
|
|
|
operand: [
|
|
|
|
|
|
|
|
(identifier) @variable.property
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: (identifier) @variable.property)
|
|
|
|
|
|
|
|
(boolean) @variable.property
|
|
|
|
|
|
|
|
(nil) @variable.property
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * capture operator
|
|
|
|
|
|
|
|
(unary_operator
|
|
|
|
|
|
|
|
operator: "&"
|
|
|
|
|
|
|
|
operand: [
|
|
|
|
|
|
|
|
(integer) @operator
|
|
|
|
|
|
|
|
(binary_operator
|
|
|
|
|
|
|
|
left: [
|
|
|
|
|
|
|
|
(call target: (dot left: (_) right: (identifier) @function))
|
|
|
|
|
|
|
|
(identifier) @function
|
|
|
|
|
|
|
|
] operator: "/" right: (integer) @operator)
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(operator_identifier) @operator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(unary_operator
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(binary_operator
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(dot
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(stab_clause
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Literals
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(nil) @constant.builtin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(boolean) @constant.builtin.boolean
|
|
|
|
|
|
|
|
|
|
|
|
[(true) (false) (nil)] @constant.builtin
|
|
|
|
[
|
|
|
|
|
|
|
|
(integer)
|
|
|
|
|
|
|
|
(float)
|
|
|
|
|
|
|
|
] @number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(alias) @type
|
|
|
|
|
|
|
|
|
|
|
|
(keyword
|
|
|
|
(call
|
|
|
|
[(keyword_literal)
|
|
|
|
target: (dot
|
|
|
|
":"] @tag)
|
|
|
|
left: (atom) @type))
|
|
|
|
|
|
|
|
|
|
|
|
(keyword
|
|
|
|
(char) @constant.character
|
|
|
|
(keyword_string
|
|
|
|
|
|
|
|
[(string_start)
|
|
|
|
|
|
|
|
(string_content)
|
|
|
|
|
|
|
|
(string_end)] @tag))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[(atom_literal)
|
|
|
|
; Quoted content
|
|
|
|
(atom_start)
|
|
|
|
|
|
|
|
(atom_content)
|
|
|
|
|
|
|
|
(atom_end)] @tag
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[(comment)
|
|
|
|
(interpolation "#{" @escape "}" @escape) @embedded
|
|
|
|
(unused_identifier)] @comment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(escape_sequence) @escape
|
|
|
|
(escape_sequence) @escape
|
|
|
|
|
|
|
|
|
|
|
|
(call function: (function_identifier) @keyword
|
|
|
|
[
|
|
|
|
(#match? @keyword "^(defmodule|defexception|defp|def|with|case|cond|raise|import|require|use|defmacrop|defmacro|defguardp|defguard|defdelegate|defstruct|alias|defimpl|defprotocol|defoverridable|receive|if|for|try|throw|unless|reraise|super|quote|unquote|unquote_splicing)$"))
|
|
|
|
(atom)
|
|
|
|
|
|
|
|
(quoted_atom)
|
|
|
|
(call function: (function_identifier) @keyword
|
|
|
|
(keyword)
|
|
|
|
[(call
|
|
|
|
(quoted_keyword)
|
|
|
|
function: (function_identifier) @function
|
|
|
|
] @string.special.symbol
|
|
|
|
(arguments
|
|
|
|
|
|
|
|
[(identifier) @variable.parameter
|
|
|
|
[
|
|
|
|
(_ (identifier) @variable.parameter)
|
|
|
|
(string)
|
|
|
|
(_ (_ (identifier) @variable.parameter))
|
|
|
|
(charlist)
|
|
|
|
(_ (_ (_ (identifier) @variable.parameter)))
|
|
|
|
] @string
|
|
|
|
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
|
|
|
|
|
|
|
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
|
|
|
|
; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
|
|
|
|
(binary_op
|
|
|
|
|
|
|
|
left:
|
|
|
|
(sigil
|
|
|
|
(call
|
|
|
|
(sigil_name) @__name__
|
|
|
|
function: (function_identifier) @function
|
|
|
|
quoted_start: _ @string
|
|
|
|
(arguments
|
|
|
|
quoted_end: _ @string
|
|
|
|
[(identifier) @variable.parameter
|
|
|
|
(#match? @__name__ "^[sS]$")) @string
|
|
|
|
(_ (identifier) @variable.parameter)
|
|
|
|
|
|
|
|
(_ (_ (identifier) @variable.parameter))
|
|
|
|
(sigil
|
|
|
|
(_ (_ (_ (identifier) @variable.parameter)))
|
|
|
|
(sigil_name) @__name__
|
|
|
|
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
|
|
|
quoted_start: _ @string.regex
|
|
|
|
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
|
|
|
|
quoted_end: _ @string.regex
|
|
|
|
|
|
|
|
(#match? @__name__ "^[rR]$")) @string.regex
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(sigil
|
|
|
|
|
|
|
|
(sigil_name) @__name__
|
|
|
|
|
|
|
|
quoted_start: _ @string.special
|
|
|
|
|
|
|
|
quoted_end: _ @string.special) @string.special
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * definition keyword
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: (identifier) @keyword
|
|
|
|
|
|
|
|
(#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * kernel or special forms keyword
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: (identifier) @keyword
|
|
|
|
|
|
|
|
(#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * function call
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: [
|
|
|
|
|
|
|
|
; local
|
|
|
|
|
|
|
|
(identifier) @function
|
|
|
|
|
|
|
|
; remote
|
|
|
|
|
|
|
|
(dot
|
|
|
|
|
|
|
|
right: (identifier) @function)
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; * just identifier in function definition
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: (identifier) @keyword
|
|
|
|
|
|
|
|
(arguments
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
(identifier) @function
|
|
|
|
|
|
|
|
(binary_operator
|
|
|
|
|
|
|
|
left: (identifier) @function
|
|
|
|
operator: "when")
|
|
|
|
operator: "when")
|
|
|
|
(binary_op
|
|
|
|
])
|
|
|
|
left: (identifier) @variable.parameter
|
|
|
|
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
|
|
|
operator: _ @function
|
|
|
|
|
|
|
|
right: (identifier) @variable.parameter)]
|
|
|
|
; * pipe into identifier (definition)
|
|
|
|
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
|
|
|
|
(call
|
|
|
|
|
|
|
|
target: (identifier) @keyword
|
|
|
|
(call (function_identifier) @keyword
|
|
|
|
(arguments
|
|
|
|
[(call
|
|
|
|
(binary_operator
|
|
|
|
function: (function_identifier) @function)
|
|
|
|
operator: "|>"
|
|
|
|
(identifier) @function
|
|
|
|
right: (identifier) @variable))
|
|
|
|
(binary_op
|
|
|
|
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
|
|
|
left:
|
|
|
|
|
|
|
|
[(call
|
|
|
|
; * pipe into identifier (function call)
|
|
|
|
function: (function_identifier) @function)
|
|
|
|
(binary_operator
|
|
|
|
(identifier) @function]
|
|
|
|
operator: "|>"
|
|
|
|
operator: "when")]
|
|
|
|
right: (identifier) @function)
|
|
|
|
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
|
|
|
|
|
|
|
|
|
|
|
|
; Identifiers
|
|
|
|
(anonymous_function
|
|
|
|
|
|
|
|
(stab_expression
|
|
|
|
; * special
|
|
|
|
left: (bare_arguments
|
|
|
|
(
|
|
|
|
[(identifier) @variable.parameter
|
|
|
|
(identifier) @constant.builtin
|
|
|
|
(_ (identifier) @variable.parameter)
|
|
|
|
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
|
|
|
|
(_ (_ (identifier) @variable.parameter))
|
|
|
|
)
|
|
|
|
(_ (_ (_ (identifier) @variable.parameter)))
|
|
|
|
|
|
|
|
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
|
|
|
; * unused
|
|
|
|
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
|
|
|
|
(
|
|
|
|
|
|
|
|
(identifier) @comment
|
|
|
|
(unary_op
|
|
|
|
(#match? @comment "^_")
|
|
|
|
operator: "@"
|
|
|
|
)
|
|
|
|
(call (identifier) @attribute
|
|
|
|
|
|
|
|
(heredoc
|
|
|
|
; * regular
|
|
|
|
[(heredoc_start)
|
|
|
|
(identifier) @variable
|
|
|
|
(heredoc_content)
|
|
|
|
|
|
|
|
(heredoc_end)] @doc))
|
|
|
|
; Comment
|
|
|
|
(#match? @attribute "^(doc|moduledoc)$"))
|
|
|
|
|
|
|
|
|
|
|
|
(comment) @comment
|
|
|
|
(module) @type
|
|
|
|
|
|
|
|
|
|
|
|
; Punctuation
|
|
|
|
(unary_op
|
|
|
|
|
|
|
|
operator: "@" @attribute
|
|
|
|
[
|
|
|
|
[(call
|
|
|
|
"%"
|
|
|
|
function: (function_identifier) @attribute)
|
|
|
|
] @punctuation
|
|
|
|
(identifier) @attribute])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(unary_op
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(binary_op
|
|
|
|
|
|
|
|
operator: _ @operator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(heredoc
|
|
|
|
|
|
|
|
[(heredoc_start)
|
|
|
|
|
|
|
|
(heredoc_content)
|
|
|
|
|
|
|
|
(heredoc_end)] @string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(string
|
|
|
|
|
|
|
|
[(string_start)
|
|
|
|
|
|
|
|
(string_content)
|
|
|
|
|
|
|
|
(string_end)] @string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(sigil_start) @string.special
|
|
|
|
|
|
|
|
(sigil_content) @string
|
|
|
|
|
|
|
|
(sigil_end) @string.special
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(interpolation
|
|
|
|
|
|
|
|
"#{" @punctuation.special
|
|
|
|
|
|
|
|
"}" @punctuation.special)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
[
|
|
|
|
","
|
|
|
|
","
|
|
|
|
"->"
|
|
|
|
";"
|
|
|
|
"."
|
|
|
|
|
|
|
|
] @punctuation.delimiter
|
|
|
|
] @punctuation.delimiter
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
[
|
|
|
@ -133,6 +221,4 @@
|
|
|
|
">>"
|
|
|
|
">>"
|
|
|
|
] @punctuation.bracket
|
|
|
|
] @punctuation.bracket
|
|
|
|
|
|
|
|
|
|
|
|
(special_identifier) @function.special
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(ERROR) @warning
|
|
|
|
(ERROR) @warning
|
|
|
|