summaryrefslogtreecommitdiff
path: root/queries/elixir
diff options
context:
space:
mode:
Diffstat (limited to 'queries/elixir')
-rw-r--r--queries/elixir/highlights.scm262
1 files changed, 118 insertions, 144 deletions
diff --git a/queries/elixir/highlights.scm b/queries/elixir/highlights.scm
index 51c57494..413ae6cc 100644
--- a/queries/elixir/highlights.scm
+++ b/queries/elixir/highlights.scm
@@ -1,180 +1,154 @@
-(identifier) @variable
-
-; _unused variables
-(unused_identifier) @comment
-
-; __MODULE__ and friends
-(special_identifier) @constant.builtin
-
-(module) @type
-
-[(atom) (keyword)] @symbol
-
-(integer) @number
-(float) @float
-
-[(true) (false)] @boolean
-
-(nil) @constant.builtin
-
-(comment) @comment
-
-[
- ","
- "."
-] @punctuation.delimiter
+(ERROR) @error
[
"("
")"
+ "<<"
+ ">>"
"["
"]"
"{"
"}"
- "<<"
- ">>"
] @punctuation.bracket
-(interpolation
- "#{" @punctuation.special
- "}" @punctuation.special) @none
-
[
- (heredoc_content)
- (sigil_content)
- (string_content)
- (string_end)
- (string_start)
-] @string
+ ","
+ "->"
+ "."
+] @punctuation.delimiter
[
- (heredoc_end)
- (heredoc_start)
- (sigil_end)
(sigil_start)
-] @string.special
+ (sigil_end)
+ (heredoc_start)
+ (heredoc_end)
+] @punctuation.special
-(escape_sequence) @string.escape
+(interpolation ["#{" "}"] @punctuation.special)
[
"after"
+ "and"
+ "catch"
"do"
+ "else"
"end"
-] @keyword
-
-[
- "and"
+ "fn"
"in"
- "not"
"not in"
+ "not"
"or"
-] @keyword.operator
+ "rescue"
+ "when"
+] @keyword
+
+[
+ (comment)
+ (unused_identifier)
+] @comment
+
+[
+ (heredoc_content)
+ (sigil_content)
+ (string)
+] @string
-; Call to a local function
-(call (function_identifier) @method)
+; __MODULE__ and friends
+(special_identifier) @constant.builtin
+
+(map ["%{" "}"] @constructor)
+
+(struct ["%" "{" "}"] @constructor)
+
+(binary_op operator: _ @operator)
-; Call to a remote (or external) function
-(dot_call
- remote: [(atom) (module)] @type
- function: (function_identifier) @method)
+(unary_op operator: _ @operator)
-(dot_call
- remote: (identifier) @variable
- function: (function_identifier) @method)
+(atom) @symbol
-"fn" @keyword.function
+(keyword) @parameter
+
+[
+ (true)
+ (false)
+] @boolean
+
+(nil) @constant.builtin
-; def, defp, defguard, ... everything that starts with def
-(call (function_identifier) @keyword.function
- (#lua-match? @keyword.function "^def%a*$"))
+(sigil) @string.special
-(call (function_identifier) @keyword.function
- (#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))
+(identifier) @variable
-"else" @conditional
+(module) @type
-(call (function_identifier) @conditional
- (#any-of? @conditional "case" "cond" "if" "unless" "with"))
+(function_identifier) @function
-(call (function_identifier) @repeat
- (#eq? @repeat "for"))
+(integer) @number
-(call (function_identifier) @include
- (#any-of? @include "alias" "import" "require" "use"))
+(float) @float
[
- "catch"
- "rescue"
-] @exception
-
-(call (function_identifier) @exception
- (#any-of? @exception "raise" "try"))
-
-; Regex sigil
-(sigil
- (sigil_start) @_sigil-type
- [(sigil_content) (escape_sequence)] @string.regex
- (sigil_end)
- (#lua-match? @_sigil-type "^~r"))
-
-"->" @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"))
-
-; Definition without arguments
-(call (function_identifier) @keyword.function
- (identifier) @function
- (#lua-match? @keyword.function "^def%a*$"))
-
-; Definition with (some) arguments and (optional) defaults
-(call (function_identifier) @keyword.function
- (call
- function: (function_identifier) @function
- (arguments))
- (#lua-match? @keyword.function "^def%a*$"))
-
-; Definition with (some) arguments and guard(s)
-(call (function_identifier) @keyword.function
- (binary_op
- left:
- (call
- function: (function_identifier) @function
- (arguments))
- operator: "when")
- (#lua-match? @keyword.function "^def%a*$"))
-
-; Definition of custom binary operator(s)
-(call (function_identifier) @keyword.function
- (binary_op
- left: (identifier) @parameter
- operator: _ @function
- right: (identifier) @parameter)
- (#any-of? @keyword.function "def" "defp"))
+ (sigil_start)
+ (sigil_end)
+] @string.special
-(ERROR) @error
+; Module attributes as "attributes"
+(unary_op operator: "@" @attribute [
+ (call function: (function_identifier) @attribute)
+ (identifier) @attribute
+])
+
+; Erlang modules (when they are the remote of a function call) are highlighted as Elixir modules
+(dot_call remote: (atom) @type)
+
+(call (function_identifier) @keyword.function (#any-of? @keyword.function
+ "def"
+ "defdelegate"
+ "defexception"
+ "defguard"
+ "defguardp"
+ "defimpl"
+ "defmacro"
+ "defmacrop"
+ "defmodule"
+ "defoverridable"
+ "defp"
+ "defprotocol"
+ "defstruct"
+) [(identifier) @function (_)]) ; 0-arity function def without parens
+
+(call (function_identifier) @include (#any-of? @include
+ "alias"
+ "import"
+ "require"
+ "use"
+))
+
+(call (function_identifier) @conditional (#any-of? @conditional
+ "case"
+ "cond"
+ "else"
+ "if"
+ "unless"
+ "with"
+ "receive"
+))
+
+(call (function_identifier) @exception (#any-of? @exception
+ "raise"
+ "reraise"
+ "throw"
+ "try"
+))
+
+(call (function_identifier) @repeat (#any-of? @repeat
+ "for"
+))
+
+(call (function_identifier) @keyword.function (#any-of? @keyword.function
+ "describe"
+ "setup"
+ "setup_all"
+ "test"
+ "using"
+))