add highlights query from elixir-lang/tree-sitter-elixir

This commit is contained in:
Michael Davis 2021-10-11 21:10:14 -05:00
parent 6c0786edc5
commit d1b434d230
No known key found for this signature in database
GPG key ID: 25D3AFE4BA2A0C49

View file

@ -1,125 +1,186 @@
["when" "and" "or" "not in" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword ; Reserved keywords
[(true) (false) (nil)] @constant.builtin ["when" "and" "or" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword
(keyword ; Operators
[(keyword_literal)
":"] @tag)
(keyword ; * doc string
(keyword_string (unary_operator
[(string_start) operator: "@" @comment.doc
(string_content) operand: (call
(string_end)] @tag)) 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)$"))
[(atom_literal) ; * module attribute
(atom_start) (unary_operator
(atom_content) operator: "@" @attribute
(atom_end)] @tag operand: [
(identifier) @attribute
(call
target: (identifier) @attribute)
(boolean) @attribute
(nil) @attribute
])
[(comment) ; * capture operand
(unused_identifier)] @comment (unary_operator
operator: "&"
operand: (integer) @operator)
(escape_sequence) @escape (operator_identifier) @operator
(call function: (function_identifier) @keyword (unary_operator
(#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)$")) operator: _ @operator)
(call function: (function_identifier) @keyword (binary_operator
[(call operator: _ @operator)
function: (function_identifier) @function
(arguments (dot
[(identifier) @variable.parameter operator: _ @operator)
(_ (identifier) @variable.parameter)
(_ (_ (identifier) @variable.parameter)) (stab_clause
(_ (_ (_ (identifier) @variable.parameter))) operator: _ @operator)
(_ (_ (_ (_ (identifier) @variable.parameter))))
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])) ; Literals
(binary_op
left: [
(call (boolean)
function: (function_identifier) @function (nil)
(arguments ] @constant
[(identifier) @variable.parameter
(_ (identifier) @variable.parameter) [
(_ (_ (identifier) @variable.parameter)) (integer)
(_ (_ (_ (identifier) @variable.parameter))) (float)
(_ (_ (_ (_ (identifier) @variable.parameter)))) ] @number
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))]))
(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") 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)]
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
(call (function_identifier) @keyword ; * pipe into identifier (definition)
[(call (call
function: (function_identifier) @function) target: (identifier) @keyword
(identifier) @function (arguments
(binary_op (binary_operator
left: operator: "|>"
[(call right: (identifier) @variable))
function: (function_identifier) @function) (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
(identifier) @function]
operator: "when")]
(#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$"))
(anonymous_function ; * pipe into identifier (function call)
(stab_expression (binary_operator
left: (bare_arguments operator: "|>"
[(identifier) @variable.parameter right: (identifier) @function)
(_ (identifier) @variable.parameter)
(_ (_ (identifier) @variable.parameter))
(_ (_ (_ (identifier) @variable.parameter)))
(_ (_ (_ (_ (identifier) @variable.parameter))))
(_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])))
(unary_op ; Identifiers
operator: "@"
(call (identifier) @attribute
(heredoc
[(heredoc_start)
(heredoc_content)
(heredoc_end)] @doc))
(#match? @attribute "^(doc|moduledoc)$"))
(module) @type ; * special
(
(identifier) @constant.builtin
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
)
(unary_op ; * unused
operator: "@" @attribute (
[(call (identifier) @comment.unused
function: (function_identifier) @attribute) (#match? @comment.unused "^_")
(identifier) @attribute]) )
(unary_op ; * regular
operator: _ @operator) (identifier) @variable
(binary_op ; Comment
operator: _ @operator)
(heredoc (comment) @comment
[(heredoc_start)
(heredoc_content)
(heredoc_end)] @string)
(string ; Punctuation
[(string_start)
(string_content)
(string_end)] @string)
(sigil_start) @string.special [
(sigil_content) @string "%"
(sigil_end) @string.special ] @punctuation
(interpolation
"#{" @punctuation.special
"}" @punctuation.special)
[ [
"," ","
"->" ";"
"."
] @punctuation.delimiter ] @punctuation.delimiter
[ [
@ -132,7 +193,3 @@
"<<" "<<"
">>" ">>"
] @punctuation.bracket ] @punctuation.bracket
(special_identifier) @function.special
(ERROR) @warning