Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8168,7 +8168,7 @@ def deconstruct_keys(keys)
# not value
#
class Not < Node
# [untyped] the statement on which to operate
# [nil | untyped] the statement on which to operate
attr_reader :statement

# [boolean] whether or not parentheses were used
Expand Down Expand Up @@ -8205,7 +8205,7 @@ def deconstruct_keys(keys)

def format(q)
q.text(parentheses ? "not(" : "not ")
q.format(statement)
q.format(statement) if statement
q.text(")") if parentheses
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2837,19 +2837,17 @@ def on_unary(operator, statement)
# parentheses they don't get reported as a paren node for some reason.

beginning = find_token(Kw, "not")
ending = statement
ending = statement || beginning
parentheses = source[beginning.location.end_char] == "("

range = beginning.location.end_char...statement.location.start_char
paren = source[range].include?("(")

if paren
if parentheses
find_token(LParen)
ending = find_token(RParen)
end

Not.new(
statement: statement,
parentheses: paren,
parentheses: parentheses,
location: beginning.location.to(ending.location)
)
else
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/not.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
%
not()
%
not ()
%
not foo
%
not(foo)
%
not (foo)