Skip to content

Commit d1dc4bd

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Fix ripper translator for __END__
ruby/prism@2792ac78ca
1 parent 00a3b71 commit d1dc4bd

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

lib/prism/lex_compat.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,6 @@ def state
225225
end
226226
end
227227

228-
# Ripper doesn't include the rest of the token in the event, so we need to
229-
# trim it down to just the content on the first line when comparing.
230-
class EndContentToken < Token
231-
def ==(other) # :nodoc:
232-
[self[0], self[1], self[2][0..self[2].index("\n")], self[3]] == other
233-
end
234-
end
235-
236228
# Tokens where state should be ignored
237229
# used for :on_comment, :on_heredoc_end, :on_embexpr_end
238230
class IgnoreStateToken < Token
@@ -680,7 +672,10 @@ def result
680672
token =
681673
case event
682674
when :on___end__
683-
EndContentToken.new([[lineno, column], event, value, lex_state])
675+
# Ripper doesn't include the rest of the token in the event, so we need to
676+
# trim it down to just the content on the first line.
677+
value = value[0..value.index("\n")]
678+
Token.new([[lineno, column], event, value, lex_state])
684679
when :on_comment
685680
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
686681
when :on_heredoc_end

test/prism/fixtures/__END__.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo
2+
__END__
3+
Available in DATA constant

0 commit comments

Comments
 (0)