Skip to content

Commit 2792ac7

Browse files
committed
Fix ripper translator for __END__
1 parent d1abb25 commit 2792ac7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-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

snapshots/__END__.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@ ProgramNode (location: (1,0)-(1,3))
2+
├── flags: ∅
3+
├── locals: []
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(1,3))
6+
├── flags: ∅
7+
└── body: (length: 1)
8+
└── @ CallNode (location: (1,0)-(1,3))
9+
├── flags: newline, variable_call, ignore_visibility
10+
├── receiver: ∅
11+
├── call_operator_loc: ∅
12+
├── name: :foo
13+
├── message_loc: (1,0)-(1,3) = "foo"
14+
├── opening_loc: ∅
15+
├── arguments: ∅
16+
├── closing_loc: ∅
17+
├── equal_loc: ∅
18+
└── block: ∅

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)