summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHParker <HParker@github.com>2023-08-25 11:12:09 -0700
committergit <svn-admin@ruby-lang.org>2023-08-25 19:11:14 +0000
commitf84690c6e22a3941fed6887b837fb79ba5da5470 (patch)
tree57f304651116a1f313a0ed75c4d58950282474a9 /lib
parent4825600da55c8cbd86361b44178670f591cb4099 (diff)
[ruby/yarp] ignore state on embexpr_end
Ripper state can carry over from the previous node type making coparison less useful https://github.com/ruby/yarp/commit/74509728d4
Diffstat (limited to 'lib')
-rw-r--r--lib/yarp/lex_compat.rb23
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/yarp/lex_compat.rb b/lib/yarp/lex_compat.rb
index 252e6bd397..37bfecd0bc 100644
--- a/lib/yarp/lex_compat.rb
+++ b/lib/yarp/lex_compat.rb
@@ -208,18 +208,9 @@ module YARP
end
end
- # It is extremely non obvious which state the parser is in when comments get
- # dispatched. Because of this we don't both comparing state when comparing
- # against other comment tokens.
- class CommentToken < Token
- def ==(other)
- self[0...-1] == other[0...-1]
- end
- end
-
- # Heredoc end tokens are emitted in an odd order, so we don't compare the
- # state on them.
- class HeredocEndToken < Token
+ # Tokens where state should be ignored
+ # used for :on_comment, :on_heredoc_end, :on_embexpr_end
+ class IgnoreStateToken < Token
def ==(other)
self[0...-1] == other[0...-1]
end
@@ -624,12 +615,12 @@ module YARP
when :on___end__
EndContentToken.new([[lineno, column], event, value, lex_state])
when :on_comment
- CommentToken.new([[lineno, column], event, value, lex_state])
+ IgnoreStateToken.new([[lineno, column], event, value, lex_state])
when :on_heredoc_end
# Heredoc end tokens can be emitted in an odd order, so we don't
# want to bother comparing the state on them.
- HeredocEndToken.new([[lineno, column], event, value, lex_state])
- when :on_embexpr_end, :on_ident
+ IgnoreStateToken.new([[lineno, column], event, value, lex_state])
+ when :on_ident
if lex_state == Ripper::EXPR_END
# If we have an identifier that follows a method name like:
#
@@ -649,6 +640,8 @@ module YARP
else
Token.new([[lineno, column], event, value, lex_state])
end
+ when :on_embexpr_end
+ IgnoreStateToken.new([[lineno, column], event, value, lex_state])
when :on_ignored_nl
# Ignored newlines can occasionally have a LABEL state attached to
# them which doesn't actually impact anything. We don't mirror that