From 2792ac78cae2e2be64d894e59d3c25a22a74c07d Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sat, 17 Jan 2026 20:28:01 +0100 Subject: [PATCH] Fix ripper translator for `__END__` --- lib/prism/lex_compat.rb | 13 ++++--------- snapshots/__END__.txt | 18 ++++++++++++++++++ test/prism/fixtures/__END__.txt | 3 +++ 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 snapshots/__END__.txt create mode 100644 test/prism/fixtures/__END__.txt diff --git a/lib/prism/lex_compat.rb b/lib/prism/lex_compat.rb index 46f6130357..b7c54178ac 100644 --- a/lib/prism/lex_compat.rb +++ b/lib/prism/lex_compat.rb @@ -225,14 +225,6 @@ def state end end - # Ripper doesn't include the rest of the token in the event, so we need to - # trim it down to just the content on the first line when comparing. - class EndContentToken < Token - def ==(other) # :nodoc: - [self[0], self[1], self[2][0..self[2].index("\n")], self[3]] == other - end - end - # Tokens where state should be ignored # used for :on_comment, :on_heredoc_end, :on_embexpr_end class IgnoreStateToken < Token @@ -680,7 +672,10 @@ def result token = case event when :on___end__ - EndContentToken.new([[lineno, column], event, value, lex_state]) + # Ripper doesn't include the rest of the token in the event, so we need to + # trim it down to just the content on the first line. + value = value[0..value.index("\n")] + Token.new([[lineno, column], event, value, lex_state]) when :on_comment IgnoreStateToken.new([[lineno, column], event, value, lex_state]) when :on_heredoc_end diff --git a/snapshots/__END__.txt b/snapshots/__END__.txt new file mode 100644 index 0000000000..786532cacb --- /dev/null +++ b/snapshots/__END__.txt @@ -0,0 +1,18 @@ +@ ProgramNode (location: (1,0)-(1,3)) +├── flags: ∅ +├── locals: [] +└── statements: + @ StatementsNode (location: (1,0)-(1,3)) + ├── flags: ∅ + └── body: (length: 1) + └── @ CallNode (location: (1,0)-(1,3)) + ├── flags: newline, variable_call, ignore_visibility + ├── receiver: ∅ + ├── call_operator_loc: ∅ + ├── name: :foo + ├── message_loc: (1,0)-(1,3) = "foo" + ├── opening_loc: ∅ + ├── arguments: ∅ + ├── closing_loc: ∅ + ├── equal_loc: ∅ + └── block: ∅ diff --git a/test/prism/fixtures/__END__.txt b/test/prism/fixtures/__END__.txt new file mode 100644 index 0000000000..c0f4f28004 --- /dev/null +++ b/test/prism/fixtures/__END__.txt @@ -0,0 +1,3 @@ +foo +__END__ +Available in DATA constant