aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorMichael Davis2021-10-12 02:10:14 +0000
committerMichael Davis2021-10-17 15:50:19 +0000
commitd1b434d2304218673b7e7564f9e59910b475349c (patch)
tree9ec5d3c0e379521c7d277dc7ce583a2bba54c0a4 /runtime
parent6c0786edc575c5b70bd0d5dcbdaf083f8b5525b1 (diff)
add highlights query from elixir-lang/tree-sitter-elixir
Diffstat (limited to 'runtime')
-rw-r--r--runtime/queries/elixir/highlights.scm301
1 files changed, 179 insertions, 122 deletions
diff --git a/runtime/queries/elixir/highlights.scm b/runtime/queries/elixir/highlights.scm
index 6bf93a21..bb88e450 100644
--- a/runtime/queries/elixir/highlights.scm
+++ b/runtime/queries/elixir/highlights.scm
@@ -1,125 +1,186 @@
-["when" "and" "or" "not in" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
-
-[(true) (false) (nil)] @constant.builtin
-
-(keyword
- [(keyword_literal)
- ":"] @tag)
-
-(keyword
- (keyword_string
- [(string_start)
- (string_content)
- (string_end)] @tag))
-
-[(atom_literal)
- (atom_start)
- (atom_content)
- (atom_end)] @tag
-
-[(comment)
- (unused_identifier)] @comment
-
-(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)$"))
-
-(call function: (function_identifier) @keyword
- [(call
- function: (function_identifier) @function
- (arguments
- [(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)))))]))
+; Reserved keywords
+
+["when" "and" "or" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
+
+; Operators
+
+; * doc string
+(unary_operator
+ operator: "@" @comment.doc
+ operand: (call
+ target: (identifier) @comment.doc.__attribute__
+ (arguments
+ [
+ (string) @comment.doc
+ (charlist) @comment.doc
+ (sigil
+ quoted_start: _ @comment.doc
+ quoted_end: _ @comment.doc) @comment.doc
+ (boolean) @comment.doc
+ ]))
+ (#match? @comment.doc.__attribute__ "^(moduledoc|typedoc|doc)$"))
+
+; * module attribute
+(unary_operator
+ operator: "@" @attribute
+ operand: [
+ (identifier) @attribute
+ (call
+ target: (identifier) @attribute)
+ (boolean) @attribute
+ (nil) @attribute
+ ])
+
+; * capture operand
+(unary_operator
+ operator: "&"
+ operand: (integer) @operator)
+
+(operator_identifier) @operator
+
+(unary_operator
+ operator: _ @operator)
+
+(binary_operator
+ operator: _ @operator)
+
+(dot
+ operator: _ @operator)
+
+(stab_clause
+ operator: _ @operator)
+
+; Literals
+
+[
+ (boolean)
+ (nil)
+] @constant
+
+[
+ (integer)
+ (float)
+] @number
+
+(alias) @type
+
+(char) @constant
+
+; Quoted content
+
+(interpolation "#{" @punctuation.special "}" @punctuation.special) @embedded
+
+(escape_sequence) @string.escape
+
+[
+ (atom)
+ (quoted_atom)
+ (keyword)
+ (quoted_keyword)
+] @string.special.symbol
+
+[
+ (string)
+ (charlist)
+] @string
+
+; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters
+
+(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
+ ; remote
+ (dot
+ right: (identifier) @function)
+ ])
+
+; * just identifier in function definition
+(call
+ target: (identifier) @keyword
+ (arguments
+ [
+ (identifier) @function
+ (binary_operator
+ left: (identifier) @function
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
- [(call
- function: (function_identifier) @function)
- (identifier) @function
- (binary_op
- left:
- [(call
- function: (function_identifier) @function)
- (identifier) @function]
- operator: "when")]
- (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
-
-(anonymous_function
- (stab_expression
- left: (bare_arguments
- [(identifier) @variable.parameter
- (_ (identifier) @variable.parameter)
- (_ (_ (identifier) @variable.parameter))
- (_ (_ (_ (identifier) @variable.parameter)))
- (_ (_ (_ (_ (identifier) @variable.parameter))))
- (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
-
-(unary_op
- operator: "@"
- (call (identifier) @attribute
- (heredoc
- [(heredoc_start)
- (heredoc_content)
- (heredoc_end)] @doc))
- (#match? @attribute "^(doc|moduledoc)$"))
-
-(module) @type
-
-(unary_op
- operator: "@" @attribute
- [(call
- function: (function_identifier) @attribute)
- (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)
+ ])
+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
+
+; * pipe into identifier (definition)
+(call
+ target: (identifier) @keyword
+ (arguments
+ (binary_operator
+ operator: "|>"
+ right: (identifier) @variable))
+ (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
+
+; * pipe into identifier (function call)
+(binary_operator
+ operator: "|>"
+ right: (identifier) @function)
+
+; Identifiers
+
+; * special
+(
+ (identifier) @constant.builtin
+ (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
+)
+
+; * unused
+(
+ (identifier) @comment.unused
+ (#match? @comment.unused "^_")
+)
+
+; * regular
+(identifier) @variable
+
+; Comment
+
+(comment) @comment
+
+; Punctuation
+
+[
+ "%"
+] @punctuation
[
","
- "->"
- "."
+ ";"
] @punctuation.delimiter
[
@@ -132,7 +193,3 @@
"<<"
">>"
] @punctuation.bracket
-
-(special_identifier) @function.special
-
-(ERROR) @warning