Skip to content

Commit

Permalink
remove the need for negative highlight query
Browse files Browse the repository at this point in the history
fixes #12
  • Loading branch information
ananthakumaran committed Apr 17, 2021
1 parent ef64f8c commit 45864c5
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 157 deletions.
35 changes: 25 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -217,24 +220,36 @@ module.exports = grammar({
")"
),

paren_call: $ => seq(field("name", $.identifier), $.arguments),
paren_call: $ =>
seq(
field("function", alias($.identifier, $.function_identifier)),
$.arguments
),

call: $ =>
prec(
PREC.CALL,
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
)
Expand Down Expand Up @@ -338,7 +353,7 @@ module.exports = grammar({
field(
"function",
choice(
$.identifier,
alias($.identifier, $.function_identifier),
$.true,
$.false,
$.nil,
Expand Down Expand Up @@ -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),
Expand All @@ -391,7 +406,7 @@ module.exports = grammar({
PREC.DOT_CALL,
seq(
field(
"object",
"remote",
choice(
$.dot_call,
$.access_call,
Expand Down
56 changes: 29 additions & 27 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)$"))
Expand All @@ -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
Expand All @@ -91,7 +90,7 @@
(unary_op
operator: "@" @attribute
[(call
name: (identifier) @attribute)
function: (function_identifier) @attribute)
(identifier) @attribute])

(unary_op
Expand Down Expand Up @@ -138,6 +137,9 @@
[(identifier) @function.special
(#match? @function.special "^__.+__$")]

[(remote_identifier) @function.special
(#match? @function.special "^__.+__$")]

[(identifier) @comment
(#match? @comment "^_")]

Expand Down
6 changes: 3 additions & 3 deletions test/corpus/anonymous_function.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -190,7 +190,7 @@ fun = fn () when node() == :nonode@nohost -> true end
(block)
(binary_op
(call
(identifier)
(function_identifier)
(arguments))
(atom
(atom_literal)))))
Expand Down
6 changes: 3 additions & 3 deletions test/corpus/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ binary expression
(binary_op
(identifier)
(call
(identifier)
(function_identifier)
(arguments
(identifier)))))
(binary_op
(identifier)
(binary_op
(identifier)
(call
(identifier)
(function_identifier)
(arguments
(identifier)))))
(binary_op
(identifier)
(binary_op
(identifier)
(call
(identifier)
(function_identifier)
(arguments
(identifier)))))
(string
Expand Down
30 changes: 15 additions & 15 deletions test/corpus/block.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))))))))

Expand All @@ -83,10 +83,10 @@ end

(program
(call
(identifier)
(function_identifier)
(binary_op
(call
(identifier)
(function_identifier)
(arguments
(list
(binary_op
Expand All @@ -96,7 +96,7 @@ end
(comment)
(binary_op
(call
(identifier)
(function_identifier)
(arguments
(identifier)))
(block
Expand All @@ -123,10 +123,10 @@ end
(integer))))))))
(do_block
(call
(identifier)
(function_identifier)
(arguments
(identifier)
(call
(identifier)
(function_identifier)
(arguments
(identifier))))))))
Loading

0 comments on commit 45864c5

Please sign in to comment.