diff --git a/grammar.js b/grammar.js index bbb133f851..80e038c60f 100644 --- a/grammar.js +++ b/grammar.js @@ -36,7 +36,10 @@ function binaryOp($, assoc, precedence, operator, bare_keyword) { } function unaryOp($, assoc, precedence, operator) { - return assoc(precedence, seq(field("operator", operator), optional($._line_break), $._expression)); + return assoc( + precedence, + seq(field("operator", operator), optional($._line_break), $._expression) + ); } function blockExpression($, name) { @@ -217,7 +220,11 @@ module.exports = grammar({ ")" ), - paren_call: $ => seq(field("name", $.identifier), $.arguments), + paren_call: $ => + seq( + field("function", alias($.identifier, $.function_identifier)), + $.arguments + ), call: $ => prec( @@ -225,16 +232,24 @@ module.exports = grammar({ choice( seq( field( - "name", - choice($.identifier, $.dot_call, alias($.paren_call, $.call)) + "function", + choice( + alias($.identifier, $.function_identifier), + $.dot_call, + alias($.paren_call, $.call) + ) ), choice($._bare_arguments, $.arguments), optional(choice(seq($._terminator, $.do_block), $.do_block)) ), seq( field( - "name", - choice($.identifier, $.dot_call, alias($.paren_call, $.call)) + "function", + choice( + alias($.identifier, $.function_identifier), + $.dot_call, + alias($.paren_call, $.call) + ) ), $.do_block ) @@ -338,7 +353,7 @@ module.exports = grammar({ field( "function", choice( - $.identifier, + alias($.identifier, $.function_identifier), $.true, $.false, $.nil, @@ -369,10 +384,10 @@ module.exports = grammar({ PREC.DOT_CALL, seq( field( - "object", + "remote", choice( $.module, - $.identifier, + alias($.identifier, $.remote_identifier), $.atom, alias($._simple_dot_call, $.dot_call), alias($.paren_call, $.call), @@ -391,7 +406,7 @@ module.exports = grammar({ PREC.DOT_CALL, seq( field( - "object", + "remote", choice( $.dot_call, $.access_call, diff --git a/queries/highlights.scm b/queries/highlights.scm index 7ec0571c83..b9ec021086 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -21,31 +21,30 @@ (escape_sequence) @escape -(call (identifier) @keyword +(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 (identifier) @keyword +(call function: (function_identifier) @keyword [(call - name: (identifier) @function + function: (function_identifier) @function (arguments [(identifier) @variable.parameter - (_ !function !object !name (identifier) @variable.parameter) - (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))))])) + (_ (identifier) @variable.parameter) + (_ (_ (identifier) @variable.parameter)) + (_ (_ (_ (identifier) @variable.parameter))) + (_ (_ (_ (_ (identifier) @variable.parameter)))) + (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])) (binary_op left: - [(call - name: (identifier) @function - (arguments - [(identifier) @variable.parameter - (_ !function !object !name (identifier) @variable.parameter) - (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))))])) - (identifier) @function] + (call + function: (function_identifier) @function + (arguments + [(identifier) @variable.parameter + (_ (identifier) @variable.parameter) + (_ (_ (identifier) @variable.parameter)) + (_ (_ (_ (identifier) @variable.parameter))) + (_ (_ (_ (_ (identifier) @variable.parameter)))) + (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])) operator: "when") (binary_op left: (identifier) @variable.parameter @@ -54,14 +53,14 @@ (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$") (#match? @variable.parameter "^[^_]")) -(call (identifier) @keyword +(call (function_identifier) @keyword [(call - name: (identifier) @function) + function: (function_identifier) @function) (identifier) @function (binary_op left: [(call - name: (identifier) @function) + function: (function_identifier) @function) (identifier) @function] operator: "when")] (#match? @keyword "^(defp|def|defmacrop|defmacro|defguardp|defguard|defdelegate)$")) @@ -70,11 +69,11 @@ (stab_expression left: (bare_arguments [(identifier) @variable.parameter - (_ !function !object !name (identifier) @variable.parameter) - (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))) - (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (_ !function !object !name (identifier) @variable.parameter)))))])) + (_ (identifier) @variable.parameter) + (_ (_ (identifier) @variable.parameter)) + (_ (_ (_ (identifier) @variable.parameter))) + (_ (_ (_ (_ (identifier) @variable.parameter)))) + (_ (_ (_ (_ (_ (identifier) @variable.parameter)))))])) (#match? @variable.parameter "^[^_]")) (unary_op @@ -91,7 +90,7 @@ (unary_op operator: "@" @attribute [(call - name: (identifier) @attribute) + function: (function_identifier) @attribute) (identifier) @attribute]) (unary_op @@ -138,6 +137,9 @@ [(identifier) @function.special (#match? @function.special "^__.+__$")] +[(remote_identifier) @function.special + (#match? @function.special "^__.+__$")] + [(identifier) @comment (#match? @comment "^_")] diff --git a/test/corpus/anonymous_function.txt b/test/corpus/anonymous_function.txt index de044a25e1..36d8df0505 100644 --- a/test/corpus/anonymous_function.txt +++ b/test/corpus/anonymous_function.txt @@ -158,14 +158,14 @@ end) (program (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier) (anonymous_function (stab_expression (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -190,7 +190,7 @@ fun = fn () when node() == :nonode@nohost -> true end (block) (binary_op (call - (identifier) + (function_identifier) (arguments)) (atom (atom_literal))))) diff --git a/test/corpus/binary.txt b/test/corpus/binary.txt index f35b9724cc..85077b1024 100644 --- a/test/corpus/binary.txt +++ b/test/corpus/binary.txt @@ -17,7 +17,7 @@ binary expression (binary_op (identifier) (call - (identifier) + (function_identifier) (arguments (identifier))))) (binary_op @@ -25,7 +25,7 @@ binary expression (binary_op (identifier) (call - (identifier) + (function_identifier) (arguments (identifier))))) (binary_op @@ -33,7 +33,7 @@ binary expression (binary_op (identifier) (call - (identifier) + (function_identifier) (arguments (identifier))))) (string diff --git a/test/corpus/block.txt b/test/corpus/block.txt index c7eff7ac4e..98de4ccdc0 100644 --- a/test/corpus/block.txt +++ b/test/corpus/block.txt @@ -14,22 +14,22 @@ end (program (unary_op (call - (identifier) + (function_identifier) (binary_op (call - (identifier) + (function_identifier) (arguments)) (call - (identifier) + (function_identifier) (arguments))))) (call - (identifier) + (function_identifier) (identifier) (do_block (comment) (dot_call (module) - (identifier) + (function_identifier) (arguments (atom (atom_literal)) @@ -48,23 +48,23 @@ end (program (call - (identifier) + (function_identifier) (binary_op (call - (identifier) + (function_identifier) (arguments (identifier))) (call - (identifier) + (function_identifier) (arguments (identifier)))) (do_block (call - (identifier) + (function_identifier) (arguments (identifier) (call - (identifier) + (function_identifier) (arguments (identifier)))))))) @@ -83,10 +83,10 @@ end (program (call - (identifier) + (function_identifier) (binary_op (call - (identifier) + (function_identifier) (arguments (list (binary_op @@ -96,7 +96,7 @@ end (comment) (binary_op (call - (identifier) + (function_identifier) (arguments (identifier))) (block @@ -123,10 +123,10 @@ end (integer)))))))) (do_block (call - (identifier) + (function_identifier) (arguments (identifier) (call - (identifier) + (function_identifier) (arguments (identifier)))))))) diff --git a/test/corpus/call.txt b/test/corpus/call.txt index a692542c9d..37d68b331d 100644 --- a/test/corpus/call.txt +++ b/test/corpus/call.txt @@ -9,7 +9,7 @@ A.B.c("a") (program (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -34,7 +34,7 @@ Module.func!( (program (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier) (keyword_list @@ -82,7 +82,7 @@ a.()() (program (call (dot_call - (identifier) + (remote_identifier) (arguments)) (arguments))) @@ -111,7 +111,7 @@ a.and (program (dot_call - (identifier))) + (remote_identifier))) ================================================================================ access call followed by dot call @@ -127,7 +127,7 @@ cover[:tool].start(compile_path, cover) (identifier) (atom (atom_literal))) - (identifier) + (function_identifier) (arguments (identifier) (identifier)))) @@ -149,35 +149,35 @@ end (program (call - (identifier) + (function_identifier) (do_block (dot_call (call - (identifier) + (function_identifier) (arguments (identifier))) - (identifier) + (function_identifier) (arguments (anonymous_function (stab_expression (call - (identifier) + (function_identifier) (arguments (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier))))))) (call - (identifier) + (function_identifier) (arguments (dot_call (module) - (identifier) + (function_identifier) (arguments (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier) (unary_op @@ -197,11 +197,11 @@ end (program (call - (identifier) + (function_identifier) (true) (do_block (call - (identifier) + (function_identifier) (module) (keyword_list (keyword @@ -229,13 +229,13 @@ captured arg dot call (integer)) (dot_call (module) - (identifier) + (function_identifier) (arguments (unary_op (dot_call (unary_op (integer)) - (identifier))))))) + (function_identifier))))))) ================================================================================ captured arg qualified dot call @@ -248,7 +248,7 @@ Enum.reduce(funcs, result, & &1.(&2)) (program (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier) (identifier) @@ -270,7 +270,7 @@ alias ExUnit.{FailuresManifest, Test} (program (call - (identifier) + (function_identifier) (dot_call (module) (tuple @@ -287,7 +287,7 @@ import Kernel, except: [@: 1, defmodule: 2, def: 1, def: 2, defp: 2, defmacro: 1 (program (call - (identifier) + (function_identifier) (module) (keyword_list (keyword @@ -332,7 +332,7 @@ capture mfa (binary_op (dot_call (module) - (identifier)) + (function_identifier)) (integer)))) ================================================================================ @@ -410,7 +410,7 @@ h(== / 2) (program (call - (identifier) + (function_identifier) (arguments (binary_op (integer))))) @@ -429,7 +429,7 @@ assert_diff( (program (call - (identifier) + (function_identifier) (arguments (binary_op (struct @@ -470,14 +470,14 @@ assert (1..3).last == 3 (program (call - (identifier) + (function_identifier) (binary_op (dot_call (paren_expr (binary_op (integer) (integer))) - (identifier)) + (function_identifier)) (integer)))) ================================================================================ @@ -511,7 +511,7 @@ map call (keyword_literal)) (atom (atom_literal)))) - (identifier))) + (function_identifier))) ================================================================================ quoted struct @@ -525,11 +525,11 @@ end (program (call - (identifier) + (function_identifier) (do_block (struct (call - (identifier) + (function_identifier) (arguments (module))) (keyword_list @@ -549,10 +549,10 @@ Macro.to_string(quote(do: Foo."bar baz"().""())) == ~s/Foo."bar baz"().""()/ (binary_op (dot_call (module) - (identifier) + (function_identifier) (arguments (call - (identifier) + (function_identifier) (arguments (keyword_list (keyword @@ -600,12 +600,12 @@ inspect(&__MODULE__."weirdly named/fun-"/0) (program (call - (identifier) + (function_identifier) (arguments (unary_op (binary_op (dot_call - (identifier) + (remote_identifier) (string (string_start) (string_content) @@ -622,7 +622,7 @@ is_function(&and/2) (program (call - (identifier) + (function_identifier) (arguments (unary_op (binary_op @@ -639,7 +639,7 @@ b (program (call - (identifier) + (function_identifier) (identifier))) ================================================================================ @@ -655,7 +655,7 @@ Enum.join(" ") (binary_op (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -718,7 +718,7 @@ struct call (dot_call (struct (module)) - (identifier))) + (function_identifier))) ================================================================================ bare keyword hanging comma @@ -731,7 +731,7 @@ call(a: a, b: b, (program (call - (identifier) + (function_identifier) (arguments (keyword_list (keyword @@ -753,7 +753,7 @@ IO (program (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -772,7 +772,7 @@ IO. (program (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) diff --git a/test/corpus/case.txt b/test/corpus/case.txt index 8070ceff82..6217a1175b 100644 --- a/test/corpus/case.txt +++ b/test/corpus/case.txt @@ -11,7 +11,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression @@ -41,7 +41,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression @@ -68,7 +68,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression @@ -82,8 +82,8 @@ end (bare_arguments (integer)) (dot_call - (identifier) - (identifier) + (remote_identifier) + (function_identifier) (arguments)) (integer))))) @@ -100,7 +100,7 @@ end (program (call - (identifier) + (function_identifier) (integer) (do_block (stab_expression @@ -108,7 +108,7 @@ end (binary_op (identifier) (call - (identifier) + (function_identifier) (arguments (identifier))))) (string @@ -141,7 +141,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression @@ -153,7 +153,7 @@ end (string_end)) (identifier))) (call - (identifier) + (function_identifier) (arguments (identifier) (identifier)))) @@ -165,7 +165,7 @@ end (string_content) (string_end)))) (call - (identifier) + (function_identifier) (arguments (identifier))))))) @@ -184,7 +184,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression @@ -235,14 +235,14 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (stab_expression (bare_arguments (integer)) (call - (identifier) + (function_identifier) (arguments (list (binary_op @@ -262,7 +262,7 @@ end (unary_op (integer))) (call - (identifier) + (function_identifier) (arguments (list (binary_op @@ -295,7 +295,7 @@ end (program (call - (identifier) + (function_identifier) (integer) (do_block (stab_expression diff --git a/test/corpus/cond.txt b/test/corpus/cond.txt index a647581700..c817dcf407 100644 --- a/test/corpus/cond.txt +++ b/test/corpus/cond.txt @@ -11,7 +11,7 @@ end (program (call - (identifier) + (function_identifier) (do_block (stab_expression (bare_arguments @@ -40,7 +40,7 @@ end (program (call - (identifier) + (function_identifier) (do_block (stab_expression (bare_arguments @@ -66,7 +66,7 @@ end (program (call - (identifier) + (function_identifier) (do_block (stab_expression (bare_arguments @@ -79,8 +79,8 @@ end (bare_arguments (integer)) (dot_call - (identifier) - (identifier) + (remote_identifier) + (function_identifier) (arguments)) (integer))))) @@ -99,7 +99,7 @@ end (program (call - (identifier) + (function_identifier) (do_block (stab_expression (bare_arguments @@ -113,7 +113,7 @@ end (atom_literal)) (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier)))))) (integer)) diff --git a/test/corpus/data_types.txt b/test/corpus/data_types.txt index 1b67192fc1..50b72da597 100644 --- a/test/corpus/data_types.txt +++ b/test/corpus/data_types.txt @@ -431,7 +431,7 @@ eval_binds(CONFIG: config, SCRIPT: script) (program (call - (identifier) + (function_identifier) (arguments (keyword_list (keyword @@ -593,7 +593,7 @@ r""" (program (call - (identifier) + (function_identifier) (heredoc (heredoc_start) (heredoc_content) @@ -623,7 +623,7 @@ raise ArgumentError, (program (call - (identifier) + (function_identifier) (module) (keyword_list (keyword diff --git a/test/corpus/error.txt b/test/corpus/error.txt index c7aa52904b..6c35517def 100644 --- a/test/corpus/error.txt +++ b/test/corpus/error.txt @@ -8,7 +8,7 @@ call(, k: t) (program (call - (identifier) + (function_identifier) (arguments (ERROR) (keyword_list diff --git a/test/corpus/expression.txt b/test/corpus/expression.txt index 6e5077a7dc..af7cc57702 100644 --- a/test/corpus/expression.txt +++ b/test/corpus/expression.txt @@ -8,7 +8,7 @@ y(+1) (program (call - (identifier) + (function_identifier) (arguments (unary_op (integer))))) diff --git a/test/corpus/function.txt b/test/corpus/function.txt index 5098dc3725..2208731215 100644 --- a/test/corpus/function.txt +++ b/test/corpus/function.txt @@ -10,10 +10,10 @@ end (program (call - (identifier) + (function_identifier) (call (call - (identifier) + (function_identifier) (arguments (identifier))) (arguments @@ -23,10 +23,10 @@ end (list))) (do_block (call - (identifier) + (function_identifier) (arguments (call - (identifier) + (function_identifier) (arguments (identifier))) (identifier) @@ -46,7 +46,7 @@ end (program (call - (identifier) + (function_identifier) (identifier) (do_block (integer)))) diff --git a/test/corpus/if.txt b/test/corpus/if.txt index 63154da582..d3c534bf07 100644 --- a/test/corpus/if.txt +++ b/test/corpus/if.txt @@ -12,7 +12,7 @@ end (program (call - (identifier) + (function_identifier) (unary_op (identifier)) (do_block diff --git a/test/corpus/module.txt b/test/corpus/module.txt index 81cdaab9d4..54c79ee9dd 100644 --- a/test/corpus/module.txt +++ b/test/corpus/module.txt @@ -9,6 +9,6 @@ end (program (call - (identifier) + (function_identifier) (module) (do_block))) diff --git a/test/corpus/operator.txt b/test/corpus/operator.txt index 943e549f0b..4c0bc984a7 100644 --- a/test/corpus/operator.txt +++ b/test/corpus/operator.txt @@ -10,7 +10,7 @@ not Map.has_key?(set, tuple) (unary_op (dot_call (module) - (identifier) + (function_identifier) (arguments (identifier) (identifier))))) diff --git a/test/corpus/spec.txt b/test/corpus/spec.txt index 9d6bc68704..ca8c7ae235 100644 --- a/test/corpus/spec.txt +++ b/test/corpus/spec.txt @@ -16,19 +16,19 @@ spec with splat (program (unary_op (call - (identifier) + (function_identifier) (binary_op (binary_op (call - (identifier) + (function_identifier) (arguments (dot_call (module) - (identifier) + (function_identifier) (arguments)) (dot_call (module) - (identifier) + (function_identifier) (arguments)) (list (identifier)) @@ -47,7 +47,7 @@ spec with splat (keyword (keyword_literal)) (call - (identifier) + (function_identifier) (arguments))))))) ================================================================================ @@ -61,7 +61,7 @@ non empty list (program (unary_op (call - (identifier) + (function_identifier) (list (identifier) (identifier))))) diff --git a/test/corpus/struct.txt b/test/corpus/struct.txt index 9d72e4d854..3f8f410a22 100644 --- a/test/corpus/struct.txt +++ b/test/corpus/struct.txt @@ -55,5 +55,5 @@ with dot call (program (struct (dot_call - (identifier) + (remote_identifier) (module)))) diff --git a/test/corpus/try.txt b/test/corpus/try.txt index 38e9f8655a..4f5486cc5d 100644 --- a/test/corpus/try.txt +++ b/test/corpus/try.txt @@ -21,10 +21,10 @@ end (program (call - (identifier) + (function_identifier) (do_block (call - (identifier) + (function_identifier) (arguments (identifier))) (rescue_block @@ -33,7 +33,7 @@ end (module)) (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -45,14 +45,14 @@ end (identifier)) (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) (string_content) (interpolation (call - (identifier) + (function_identifier) (arguments (identifier)))) (string_end)))))) @@ -62,21 +62,21 @@ end (identifier)) (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) (string_content) (interpolation (call - (identifier) + (function_identifier) (arguments (identifier)))) (string_end)))))) (after_block (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) @@ -97,11 +97,11 @@ end (program (call - (identifier) + (function_identifier) (do_block (dot_call (module) - (identifier)) + (function_identifier)) (rescue_block (stab_expression (bare_arguments @@ -126,10 +126,10 @@ end (program (call - (identifier) + (function_identifier) (do_block (call - (identifier) + (function_identifier) (arguments (atom (atom_literal)))) @@ -141,14 +141,14 @@ end (identifier)) (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) (string_content) (interpolation (call - (identifier) + (function_identifier) (arguments (identifier)))) (string_end))))))))) @@ -173,7 +173,7 @@ end (program (call - (identifier) + (function_identifier) (do_block (binary_op (integer) @@ -218,10 +218,10 @@ end (program (call - (identifier) + (function_identifier) (do_block (call - (identifier) + (function_identifier) (arguments (string (string_start) @@ -230,7 +230,7 @@ end (after_block (dot_call (module) - (identifier) + (function_identifier) (arguments (string (string_start) diff --git a/test/highlight/sandbox.ex b/test/highlight/sandbox.ex index 213aea3dee..8346bdf669 100644 --- a/test/highlight/sandbox.ex +++ b/test/highlight/sandbox.ex @@ -713,6 +713,16 @@ defmodule Long.Module.Name do # ^ tag # ^ constant.builtin + def xyz when x == nil, do: nil +# ^ keyword +# ^ function +# ^ keyword +# ^ operator +# ^ constant.builtin +# ^ punctuation.delimiter +# ^ tag +# ^ constant.builtin + @doc false # ^ attribute # ^ attribute @@ -1057,6 +1067,8 @@ defprotocol Useless do # ^ punctuation.bracket # ^ variable.parameter # ^ punctuation.bracket + + def func3(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) end defimpl Useless, for: Atom do