Merge pull request #830 from the-mikedavis/official-elixir-tree-sitter
prefer elixir-lang/tree-sitter-elixir
This commit is contained in:
commit
a03b12530c
4 changed files with 190 additions and 103 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -84,7 +84,7 @@
|
||||||
shallow = true
|
shallow = true
|
||||||
[submodule "helix-syntax/languages/tree-sitter-elixir"]
|
[submodule "helix-syntax/languages/tree-sitter-elixir"]
|
||||||
path = helix-syntax/languages/tree-sitter-elixir
|
path = helix-syntax/languages/tree-sitter-elixir
|
||||||
url = https://github.com/IceDragon200/tree-sitter-elixir
|
url = https://github.com/elixir-lang/tree-sitter-elixir
|
||||||
shallow = true
|
shallow = true
|
||||||
[submodule "helix-syntax/languages/tree-sitter-nix"]
|
[submodule "helix-syntax/languages/tree-sitter-nix"]
|
||||||
path = helix-syntax/languages/tree-sitter-nix
|
path = helix-syntax/languages/tree-sitter-nix
|
||||||
|
|
|
@ -119,6 +119,7 @@ We use a similar set of scopes as
|
||||||
- `special`
|
- `special`
|
||||||
- `path`
|
- `path`
|
||||||
- `url`
|
- `url`
|
||||||
|
- `symbol` - Erlang/Elixir atoms, Ruby symbols, Clojure keywords
|
||||||
|
|
||||||
- `comment` - Code comments
|
- `comment` - Code comments
|
||||||
- `line` - Single line comments (`//`)
|
- `line` - Single line comments (`//`)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 295e62a43b92cea909cfabe57e8818d177f4857b
|
Subproject commit f5d7bda543da788bd507b05bd722627dde66c9ec
|
|
@ -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.
|
||||||
|
|
||||||
[(true) (false) (nil)] @constant.builtin
|
; Reserved keywords
|
||||||
|
|
||||||
(keyword
|
["when" "and" "or" "not" "in" "not in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
|
||||||
[(keyword_literal)
|
|
||||||
":"] @tag)
|
|
||||||
|
|
||||||
(keyword
|
; Operators
|
||||||
(keyword_string
|
|
||||||
[(string_start)
|
|
||||||
(string_content)
|
|
||||||
(string_end)] @tag))
|
|
||||||
|
|
||||||
[(atom_literal)
|
; * doc string
|
||||||
(atom_start)
|
(unary_operator
|
||||||
(atom_content)
|
operator: "@" @comment.block.documentation
|
||||||
(atom_end)] @tag
|
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)$"))
|
||||||
|
|
||||||
[(comment)
|
; * module attribute
|
||||||
(unused_identifier)] @comment
|
(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
|
||||||
|
|
||||||
|
[
|
||||||
|
(integer)
|
||||||
|
(float)
|
||||||
|
] @number
|
||||||
|
|
||||||
|
(alias) @type
|
||||||
|
|
||||||
|
(call
|
||||||
|
target: (dot
|
||||||
|
left: (atom) @type))
|
||||||
|
|
||||||
|
(char) @constant.character
|
||||||
|
|
||||||
|
; Quoted content
|
||||||
|
|
||||||
|
(interpolation "#{" @escape "}" @escape) @embedded
|
||||||
|
|
||||||
(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)
|
||||||
|
(keyword)
|
||||||
|
(quoted_keyword)
|
||||||
|
] @string.special.symbol
|
||||||
|
|
||||||
(call function: (function_identifier) @keyword
|
[
|
||||||
[(call
|
(string)
|
||||||
function: (function_identifier) @function
|
(charlist)
|
||||||
(arguments
|
] @string
|
||||||
[(identifier) @variable.parameter
|
|
||||||
(_ (identifier) @variable.parameter)
|
|
||||||
(_ (_ (identifier) @variable.parameter))
|
|
||||||
(_ (_ (_ (identifier) @variable.parameter)))
|
|
||||||
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
|
||||||
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
|
|
||||||
(binary_op
|
|
||||||
left:
|
|
||||||
(call
|
|
||||||
function: (function_identifier) @function
|
|
||||||
(arguments
|
|
||||||
[(identifier) @variable.parameter
|
|
||||||
(_ (identifier) @variable.parameter)
|
|
||||||
(_ (_ (identifier) @variable.parameter))
|
|
||||||
(_ (_ (_ (identifier) @variable.parameter)))
|
|
||||||
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
|
||||||
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
|
|
||||||
operator: "when")
|
|
||||||
(binary_op
|
|
||||||
left: (identifier) @variable.parameter
|
|
||||||
operator: _ @function
|
|
||||||
right: (identifier) @variable.parameter)]
|
|
||||||
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
|
|
||||||
|
|
||||||
(call (function_identifier) @keyword
|
; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
|
||||||
[(call
|
|
||||||
function: (function_identifier) @function)
|
(sigil
|
||||||
|
(sigil_name) @__name__
|
||||||
|
quoted_start: _ @string
|
||||||
|
quoted_end: _ @string
|
||||||
|
(#match? @__name__ "^[sS]$")) @string
|
||||||
|
|
||||||
|
(sigil
|
||||||
|
(sigil_name) @__name__
|
||||||
|
quoted_start: _ @string.regex
|
||||||
|
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
|
(identifier) @function
|
||||||
(binary_op
|
; remote
|
||||||
left:
|
(dot
|
||||||
[(call
|
right: (identifier) @function)
|
||||||
function: (function_identifier) @function)
|
])
|
||||||
(identifier) @function]
|
|
||||||
operator: "when")]
|
|
||||||
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
|
|
||||||
|
|
||||||
(anonymous_function
|
; * just identifier in function definition
|
||||||
(stab_expression
|
(call
|
||||||
left: (bare_arguments
|
target: (identifier) @keyword
|
||||||
[(identifier) @variable.parameter
|
(arguments
|
||||||
(_ (identifier) @variable.parameter)
|
[
|
||||||
(_ (_ (identifier) @variable.parameter))
|
(identifier) @function
|
||||||
(_ (_ (_ (identifier) @variable.parameter)))
|
(binary_operator
|
||||||
(_ (_ (_ (_ (identifier) @variable.parameter))))
|
left: (identifier) @function
|
||||||
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
|
operator: "when")
|
||||||
|
])
|
||||||
|
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
||||||
|
|
||||||
(unary_op
|
; * pipe into identifier (definition)
|
||||||
operator: "@"
|
(call
|
||||||
(call (identifier) @attribute
|
target: (identifier) @keyword
|
||||||
(heredoc
|
(arguments
|
||||||
[(heredoc_start)
|
(binary_operator
|
||||||
(heredoc_content)
|
operator: "|>"
|
||||||
(heredoc_end)] @doc))
|
right: (identifier) @variable))
|
||||||
(#match? @attribute "^(doc|moduledoc)$"))
|
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
||||||
|
|
||||||
(module) @type
|
; * pipe into identifier (function call)
|
||||||
|
(binary_operator
|
||||||
|
operator: "|>"
|
||||||
|
right: (identifier) @function)
|
||||||
|
|
||||||
(unary_op
|
; Identifiers
|
||||||
operator: "@" @attribute
|
|
||||||
[(call
|
|
||||||
function: (function_identifier) @attribute)
|
|
||||||
(identifier) @attribute])
|
|
||||||
|
|
||||||
(unary_op
|
; * special
|
||||||
operator: _ @operator)
|
(
|
||||||
|
(identifier) @constant.builtin
|
||||||
|
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
|
||||||
|
)
|
||||||
|
|
||||||
(binary_op
|
; * unused
|
||||||
operator: _ @operator)
|
(
|
||||||
|
(identifier) @comment
|
||||||
|
(#match? @comment "^_")
|
||||||
|
)
|
||||||
|
|
||||||
(heredoc
|
; * regular
|
||||||
[(heredoc_start)
|
(identifier) @variable
|
||||||
(heredoc_content)
|
|
||||||
(heredoc_end)] @string)
|
|
||||||
|
|
||||||
(string
|
; Comment
|
||||||
[(string_start)
|
|
||||||
(string_content)
|
|
||||||
(string_end)] @string)
|
|
||||||
|
|
||||||
(sigil_start) @string.special
|
(comment) @comment
|
||||||
(sigil_content) @string
|
|
||||||
(sigil_end) @string.special
|
|
||||||
|
|
||||||
(interpolation
|
; Punctuation
|
||||||
"#{" @punctuation.special
|
|
||||||
"}" @punctuation.special)
|
[
|
||||||
|
"%"
|
||||||
|
] @punctuation
|
||||||
|
|
||||||
[
|
[
|
||||||
","
|
","
|
||||||
"->"
|
";"
|
||||||
"."
|
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -133,6 +221,4 @@
|
||||||
">>"
|
">>"
|
||||||
] @punctuation.bracket
|
] @punctuation.bracket
|
||||||
|
|
||||||
(special_identifier) @function.special
|
|
||||||
|
|
||||||
(ERROR) @warning
|
(ERROR) @warning
|
||||||
|
|
Loading…
Add table
Reference in a new issue