aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kempkens <daniel+git@kempkens.io>2021-05-14 21:23:58 +0200
committerStephan Seitz <stephan.lauf@yahoo.de>2021-05-18 19:10:06 +0200
commite7e1db38cd966ea1e382c321dd589378393ff186 (patch)
tree53e1db7efc6bfb47a4d1da1fca633c4d36a9a087
parenthighlights(c/c++): "..." also exists in C (variadic macros) (diff)
downloadnvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar.gz
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar.bz2
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar.lz
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar.xz
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.tar.zst
nvim-treesitter-e7e1db38cd966ea1e382c321dd589378393ff186.zip
Initial Elixir support
-rw-r--r--README.md1
-rw-r--r--lua/nvim-treesitter/parsers.lua8
-rw-r--r--queries/elixir/highlights.scm190
-rw-r--r--queries/elixir/indents.scm28
-rw-r--r--queries/elixir/injections.scm1
-rw-r--r--queries/elixir/locals.scm95
6 files changed, 323 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1dd531f86..aab7bb77f 100644
--- a/README.md
+++ b/README.md
@@ -146,6 +146,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [dart](https://github.com/UserNobody14/tree-sitter-dart) (maintained by @Akin909)
- [x] [devicetree](https://github.com/joelspadin/tree-sitter-devicetree) (maintained by @jedrzejboczar)
- [x] [dockerfile](https://github.com/camdencheek/tree-sitter-dockerfile) (maintained by @camdencheek)
+- [x] [elixir](https://github.com/ananthakumaran/tree-sitter-elixir) (maintained by @nifoc)
- [ ] [elm](https://github.com/elm-tooling/tree-sitter-elm)
- [x] [erlang](https://github.com/AbstractMachinesLab/tree-sitter-erlang) (maintained by @ostera)
- [x] [fennel](https://github.com/travonted/tree-sitter-fennel) (maintained by @TravonteD)
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index a4942dddd..ae2dfbf23 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -238,6 +238,14 @@ list.erlang = {
maintainers = { '@ostera' },
}
+list.elixir = {
+ install_info = {
+ url = "https://github.com/ananthakumaran/tree-sitter-elixir",
+ files = { "src/parser.c", "src/scanner.cc" },
+ },
+ maintainers = { '@nifoc' },
+}
+
list.ocaml = {
install_info = {
url = "https://github.com/tree-sitter/tree-sitter-ocaml",
diff --git a/queries/elixir/highlights.scm b/queries/elixir/highlights.scm
new file mode 100644
index 000000000..7fcd34ac8
--- /dev/null
+++ b/queries/elixir/highlights.scm
@@ -0,0 +1,190 @@
+(identifier) @variable
+
+(interpolation
+ "#{" @punctuation.special
+ "}" @punctuation.special) @none
+
+[
+ "after"
+ "do"
+ "end"
+] @keyword
+
+[
+ "and"
+ "in"
+ "not"
+ "not in"
+ "or"
+] @keyword.operator
+
+(call (function_identifier) @method)
+
+(call (function_identifier) @keyword
+ (#any-of? @keyword
+ "quote"
+ "receive"
+ "self"
+ "super"
+ "unquote"
+ "unquote_splicing"
+ "with"
+ "assert"
+ "assert_in_delta"
+ "assert_raise"
+ "assert_receive"
+ "assert_received"
+ "catch_error"
+ "catch_exit"
+ "catch_throw"
+ "flunk"
+ "refute"
+ "refute_in_delta"
+ "refute_receive"
+ "refute_received"))
+
+"fn" @keyword.function
+
+(call (function_identifier) @keyword.function
+ (#lua-match? @keyword.function "^def%a*$"))
+
+(call (function_identifier) @keyword.function
+ (#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))
+
+"else" @conditional
+
+(call (function_identifier) @conditional
+ (#any-of? @conditional "case" "cond" "if" "unless"))
+
+(call (function_identifier) @repeat
+ (#eq? @repeat "for"))
+
+(call (function_identifier) @include
+ (#any-of? @include "alias" "import" "require" "use"))
+
+[
+ "catch"
+ "rescue"
+] @exception
+
+(call (function_identifier) @exception
+ (#any-of? @exception "raise" "try"))
+
+[
+ (heredoc_content)
+ (sigil_content)
+ (string_content)
+ (string_end)
+ (string_start)
+] @string
+
+[
+ (heredoc_end)
+ (heredoc_start)
+ (sigil_end)
+ (sigil_start)
+] @string.special
+
+(sigil
+ (sigil_start) @_sigil-type
+ [(sigil_content) (escape_sequence)] @string.regex
+ (sigil_end)
+ (#lua-match? @_sigil-type "^~r"))
+
+(module) @type
+
+[(atom) (keyword)] @symbol
+
+(escape_sequence) @string.escape
+(integer) @number
+(float) @float
+
+[(true) (false)] @boolean
+
+(nil) @constant.builtin
+
+(comment) @comment
+
+"->" @operator
+
+(unary_op
+ operator: _ @operator)
+
+(binary_op
+ operator: _ @operator)
+
+(unary_op
+ operator: "@" @attribute
+ [(call
+ function: (function_identifier) @attribute)
+ (identifier) @attribute])
+
+(unary_op
+ operator: "@"
+ (call (function_identifier) @attribute
+ (heredoc
+ [(heredoc_start)
+ (heredoc_content)
+ (heredoc_end)] @string))
+ (#any-of? @attribute "doc" "moduledoc"))
+
+(unary_op
+ operator: "@"
+ (call (function_identifier) @attribute
+ (binary_op
+ left: (identifier) @method))
+ (#eq? @attribute "spec"))
+
+[
+ ","
+ "."
+] @punctuation.delimiter
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+ "<<"
+ ">>"
+] @punctuation.bracket
+
+(dot_call
+ remote: [(atom) (module)] @type
+ function: (function_identifier) @method)
+
+(call (function_identifier) @keyword.function
+ [(call
+ (function_identifier) @function)
+ (call
+ function: (function_identifier) @function
+ (arguments
+ [(identifier) @parameter
+ (binary_op
+ left: (identifier) @parameter)]))
+ (identifier) @function
+ (binary_op
+ left:
+ [(call
+ function: (function_identifier) @function
+ (arguments
+ [(identifier) @parameter
+ (binary_op
+ left: (identifier) @parameter)]))
+ (identifier) @function]
+ operator: "when")
+ (binary_op
+ left: (identifier)
+ operator: _ @function
+ right: (identifier))]
+ (#lua-match? @keyword.function "^def%a*$"))
+
+((identifier) @comment
+ (#lua-match? @comment "^_[%a%d_]*$"))
+
+((identifier) @constant.builtin
+ (#lua-match? @constant.builtin "^__[%a%d_]+__$"))
+
+(ERROR) @error
diff --git a/queries/elixir/indents.scm b/queries/elixir/indents.scm
new file mode 100644
index 000000000..ef0db3907
--- /dev/null
+++ b/queries/elixir/indents.scm
@@ -0,0 +1,28 @@
+[
+ (arguments)
+ (call)
+ (do_block)
+ (list)
+ (map)
+ (stab_expression)
+] @indent
+
+(stab_expression
+ right: (_) @indent)
+
+[
+ "("
+ ")"
+ "{"
+ "}"
+ "["
+ "]"
+ (after_block)
+ (catch_block)
+ (else_block)
+ (rescue_block)
+ "do"
+ "end"
+] @branch
+
+(comment) @ignore
diff --git a/queries/elixir/injections.scm b/queries/elixir/injections.scm
new file mode 100644
index 000000000..4bb7d675d
--- /dev/null
+++ b/queries/elixir/injections.scm
@@ -0,0 +1 @@
+(comment) @comment
diff --git a/queries/elixir/locals.scm b/queries/elixir/locals.scm
new file mode 100644
index 000000000..2857249f9
--- /dev/null
+++ b/queries/elixir/locals.scm
@@ -0,0 +1,95 @@
+[
+ (after_block)
+ (catch_block)
+ (do_block)
+ (stab_expression)
+ (rescue_block)
+] @scope
+
+(identifier) @reference
+
+(call
+ function: (function_identifier) @_call-name
+ (module) @definition.type
+ (#eq? @_call-name "defmodule"))
+
+(call
+ function: (function_identifier) @_call-name
+ (call
+ function: (function_identifier) @definition.function)
+ (#lua-match? @_call-name "^defp?$"))
+
+(call
+ function: (function_identifier) @_call-name
+ (call
+ function: (function_identifier) @definition.function
+ (arguments
+ [(identifier) @definition.parameter
+ (tuple
+ (identifier) @definition.parameter)
+ (list
+ (identifier) @definition.parameter)
+ (map
+ (keyword_list
+ (identifier) @definition.parameter))
+ (struct
+ (keyword_list
+ (identifier) @definition.parameter))
+ (binary_op
+ left: (identifier) @definition.parameter
+ operator: "\\\\")]
+ (#lua-match? @definition.parameter "^[^_]")))
+ (#lua-match? @_call-name "^defp?$"))
+
+(call
+ function: (function_identifier) @_call-name
+ (binary_op
+ left: (call
+ function: (function_identifier) @definition.function
+ (arguments
+ [(identifier) @definition.parameter
+ (tuple
+ (identifier) @definition.parameter)
+ (list
+ (identifier) @definition.parameter)
+ (map
+ (keyword_list
+ (identifier) @definition.parameter))
+ (struct
+ (keyword_list
+ (identifier) @definition.parameter))]
+ (#lua-match? @definition.parameter "^[^_]")))
+ operator: "when")
+ (#lua-match? @_call-name "^defp?$"))
+
+(binary_op
+ left:
+ [(identifier) @definition.var
+ (tuple
+ (identifier) @definition.var)
+ (list
+ (identifier) @definition.var)
+ (map
+ (keyword_list
+ (identifier) @definition.var))
+ (struct
+ (keyword_list
+ (identifier) @definition.var))]
+ operator: "="
+ (#lua-match? @definition.var "^[^_]"))
+
+(stab_expression
+ left:
+ (bare_arguments
+ [(identifier) @definition.var
+ (tuple
+ (identifier) @definition.var)
+ (list
+ (identifier) @definition.var)
+ (map
+ (keyword_list
+ (identifier) @definition.var))
+ (struct
+ (keyword_list
+ (identifier) @definition.var))])
+ (#lua-match? @definition.var "^[^_]"))