From f84690c6e22a3941fed6887b837fb79ba5da5470 Mon Sep 17 00:00:00 2001 From: HParker Date: Fri, 25 Aug 2023 11:12:09 -0700 Subject: [PATCH] [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 --- lib/yarp/lex_compat.rb | 23 ++++++++--------------- 1 file 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