diff options
| author | Daniel Kempkens <daniel+git@kempkens.io> | 2021-05-17 20:34:05 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2021-05-18 19:10:06 +0200 |
| commit | a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3 (patch) | |
| tree | fcc0a74c9155c9f342ac130b2b6f0c5ab3aaef04 /queries/elixir | |
| parent | Use #any-of? in locals (diff) | |
| download | nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar.gz nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar.bz2 nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar.lz nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar.xz nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.tar.zst nvim-treesitter-a98e5c1f4f00b4a129a1b1393ef0b504f2d52dd3.zip | |
Refactor highlights and locals queries
Diffstat (limited to 'queries/elixir')
| -rw-r--r-- | queries/elixir/highlights.scm | 195 | ||||
| -rw-r--r-- | queries/elixir/locals.scm | 105 |
2 files changed, 142 insertions, 158 deletions
diff --git a/queries/elixir/highlights.scm b/queries/elixir/highlights.scm index 7fcd34ac8..106cf3a1d 100644 --- a/queries/elixir/highlights.scm +++ b/queries/elixir/highlights.scm @@ -1,10 +1,62 @@ (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 + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "<<" + ">>" +] @punctuation.bracket + (interpolation "#{" @punctuation.special "}" @punctuation.special) @none [ + (heredoc_content) + (sigil_content) + (string_content) + (string_end) + (string_start) +] @string + +[ + (heredoc_end) + (heredoc_start) + (sigil_end) + (sigil_start) +] @string.special + +(escape_sequence) @string.escape + +[ "after" "do" "end" @@ -18,33 +70,17 @@ "or" ] @keyword.operator +; Call to a local function (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")) +; Call to a remote (or external) function +(dot_call + remote: [(atom) (module)] @type + function: (function_identifier) @method) "fn" @keyword.function +; def, defp, defguard, ... everything that starts with def (call (function_identifier) @keyword.function (#lua-match? @keyword.function "^def%a*$")) @@ -70,41 +106,13 @@ (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 - +; Regex sigil (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 @@ -135,56 +143,47 @@ left: (identifier) @method)) (#eq? @attribute "spec")) -[ - "," - "." -] @punctuation.delimiter - -[ - "(" - ")" - "[" - "]" - "{" - "}" - "<<" - ">>" -] @punctuation.bracket - -(dot_call - remote: [(atom) (module)] @type - function: (function_identifier) @method) +; 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_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*$")) + (call + function: (function_identifier) @function + (arguments + [(identifier) @parameter + (tuple (identifier) @parameter) + (list (identifier) @parameter) + (_ + (keyword_list (identifier) @parameter)) + (binary_op + left: (identifier) @parameter + operator: "\\\\")])) + (#lua-match? @keyword.function "^def%a*$")) -((identifier) @comment - (#lua-match? @comment "^_[%a%d_]*$")) +; Definition with (some) arguments and guard(s) +(call (function_identifier) @keyword.function + (binary_op + left: + (call + function: (function_identifier) @function + (arguments + [(identifier) @parameter + (tuple (identifier) @parameter) + (list (identifier) @parameter) + (_ + (keyword_list (identifier) @parameter))])) + operator: "when") + (#lua-match? @keyword.function "^def%a*$")) -((identifier) @constant.builtin - (#lua-match? @constant.builtin "^__[%a%d_]+__$")) +; 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")) (ERROR) @error diff --git a/queries/elixir/locals.scm b/queries/elixir/locals.scm index 1162b190f..f4011d4c5 100644 --- a/queries/elixir/locals.scm +++ b/queries/elixir/locals.scm @@ -13,83 +13,68 @@ (module) @definition.type (#eq? @_call-name "defmodule")) -(call - function: (function_identifier) @_call-name - (call - function: (function_identifier) @definition.function) - (#any-of? @_call-name "def" "defp")) +; Function definition without arguments +(call (function_identifier) @_call-name + (identifier) @definition.function + (#any-of? @_call-name "def" "defp" "defguard" "defguardp")) -(call - function: (function_identifier) @_call-name +; Function definition with arguments +(call (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)) + (tuple (identifier) @definition.parameter) + (list (identifier) @definition.parameter) + (_ + (keyword_list (identifier) @definition.parameter)) (binary_op left: (identifier) @definition.parameter - operator: "\\\\")] - (#lua-match? @definition.parameter "^[^_]"))) + operator: "\\\\")])) (#any-of? @_call-name "def" "defp")) -(call - function: (function_identifier) @_call-name +; Function definition with (some) arguments and guard(s) +(call (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 "^[^_]"))) + left: + (call + function: (function_identifier) @definition.function + (arguments + [(identifier) @definition.parameter + (tuple (identifier) @definition.parameter) + (list (identifier) @definition.parameter) + (_ + (keyword_list (identifier) @definition.parameter))])) operator: "when") - (#any-of? @_call-name "def" "defp")) + (#any-of? @_call-name "def" "defp" "defguard" "defguardp")) +; Variable assignment and simple pattern matching (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 "^[^_]")) + (tuple (identifier) @definition.var) + (list (identifier) @definition.var) + (_ + (keyword_list (identifier) @definition.var))] + operator: "=") +; Simple stab expression (ex. case pattern matching) without guard(s) (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 "^[^_]")) + (tuple (identifier) @definition.var) + (list (identifier) @definition.var) + (_ + (keyword_list (identifier) @definition.var))])) + +; Simple stab expression (ex. case pattern matching) with guard(s) +(stab_expression + left: + (bare_arguments + (binary_op + left: [(identifier) @definition.var + (tuple (identifier) @definition.var) + (list (identifier) @definition.var) + (_ + (keyword_list (identifier) @definition.var))]))) |
