summaryrefslogtreecommitdiff
path: root/lib/prism/translation/parser
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2024-03-08 00:22:41 +0900
committergit <svn-admin@ruby-lang.org>2024-03-08 19:07:53 +0000
commitdd24d88473d432f166894bd6d187a6db2c27bfc5 (patch)
tree5852712b2db7641652337ac3939ea2ba64802aef /lib/prism/translation/parser
parent609bbad15da6fe91904bdcd139f9e24e3cf61d4b (diff)
[ruby/prism] Fix a token incompatibility for `Prism::Translation::Parser`
Fixes https://github.com/ruby/prism/pull/2512. This PR fixes a token incompatibility between Parser gem and `Prism::Translation::Parser` for `HEREDOC_END` with a newline. https://github.com/ruby/prism/commit/b67d1e0c6f
Diffstat (limited to 'lib/prism/translation/parser')
-rw-r--r--lib/prism/translation/parser/lexer.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb
index 7585aadd7b..b28273b03f 100644
--- a/lib/prism/translation/parser/lexer.rb
+++ b/lib/prism/translation/parser/lexer.rb
@@ -304,7 +304,11 @@ module Prism
when :tSTRING_DVAR
value = nil
when :tSTRING_END
- if token.type == :REGEXP_END
+ if token.type == :HEREDOC_END && value.end_with?("\n")
+ newline_length = value.end_with?("\r\n") ? 2 : 1
+ value = value.sub(/\r?\n\z/, '')
+ location = Range.new(source_buffer, offset_cache[token.location.start_offset], offset_cache[token.location.end_offset - newline_length])
+ elsif token.type == :REGEXP_END
value = value[0]
location = Range.new(source_buffer, offset_cache[token.location.start_offset], offset_cache[token.location.start_offset + 1])
end