Skip to content

Commit 7450972

Browse files
committed
ignore state on embexpr_end
Ripper state can carry over from the previous node type making coparison less useful
1 parent 1204466 commit 7450972

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lib/yarp/lex_compat.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,9 @@ def ==(other)
208208
end
209209
end
210210

211-
# It is extremely non obvious which state the parser is in when comments get
212-
# dispatched. Because of this we don't both comparing state when comparing
213-
# against other comment tokens.
214-
class CommentToken < Token
215-
def ==(other)
216-
self[0...-1] == other[0...-1]
217-
end
218-
end
219-
220-
# Heredoc end tokens are emitted in an odd order, so we don't compare the
221-
# state on them.
222-
class HeredocEndToken < Token
211+
# Tokens where state should be ignored
212+
# used for :on_comment, :on_heredoc_end, :on_embexpr_end
213+
class IgnoreStateToken < Token
223214
def ==(other)
224215
self[0...-1] == other[0...-1]
225216
end
@@ -619,12 +610,12 @@ def result
619610
when :on___end__
620611
EndContentToken.new([[lineno, column], event, value, lex_state])
621612
when :on_comment
622-
CommentToken.new([[lineno, column], event, value, lex_state])
613+
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
623614
when :on_heredoc_end
624615
# Heredoc end tokens can be emitted in an odd order, so we don't
625616
# want to bother comparing the state on them.
626-
HeredocEndToken.new([[lineno, column], event, value, lex_state])
627-
when :on_embexpr_end, :on_ident
617+
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
618+
when :on_ident
628619
if lex_state == Ripper::EXPR_END
629620
# If we have an identifier that follows a method name like:
630621
#
@@ -644,6 +635,8 @@ def result
644635
else
645636
Token.new([[lineno, column], event, value, lex_state])
646637
end
638+
when :on_embexpr_end
639+
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
647640
when :on_ignored_nl
648641
# Ignored newlines can occasionally have a LABEL state attached to
649642
# them which doesn't actually impact anything. We don't mirror that

0 commit comments

Comments
 (0)