[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
This commit is contained in:
parent
609bbad15d
commit
dd24d88473
@ -304,7 +304,11 @@ module Prism
|
|||||||
when :tSTRING_DVAR
|
when :tSTRING_DVAR
|
||||||
value = nil
|
value = nil
|
||||||
when :tSTRING_END
|
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]
|
value = value[0]
|
||||||
location = Range.new(source_buffer, offset_cache[token.location.start_offset], offset_cache[token.location.start_offset + 1])
|
location = Range.new(source_buffer, offset_cache[token.location.start_offset], offset_cache[token.location.start_offset + 1])
|
||||||
end
|
end
|
||||||
|
2
test/prism/fixtures/heredoc.txt
Normal file
2
test/prism/fixtures/heredoc.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<<TEXT
|
||||||
|
TEXT
|
2
test/prism/fixtures/heredoc_with_carriage_returns.txt
Normal file
2
test/prism/fixtures/heredoc_with_carriage_returns.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<<TEXT
|
||||||
|
TEXT
|
11
test/prism/snapshots/heredoc.txt
Normal file
11
test/prism/snapshots/heredoc.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
@ ProgramNode (location: (1,0)-(1,6))
|
||||||
|
├── locals: []
|
||||||
|
└── statements:
|
||||||
|
@ StatementsNode (location: (1,0)-(1,6))
|
||||||
|
└── body: (length: 1)
|
||||||
|
└── @ StringNode (location: (1,0)-(1,6))
|
||||||
|
├── flags: ∅
|
||||||
|
├── opening_loc: (1,0)-(1,6) = "<<TEXT"
|
||||||
|
├── content_loc: (2,0)-(2,0) = ""
|
||||||
|
├── closing_loc: (2,0)-(3,0) = "TEXT\n"
|
||||||
|
└── unescaped: ""
|
11
test/prism/snapshots/heredoc_with_carriage_returns.txt
Normal file
11
test/prism/snapshots/heredoc_with_carriage_returns.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
@ ProgramNode (location: (1,0)-(1,6))
|
||||||
|
├── locals: []
|
||||||
|
└── statements:
|
||||||
|
@ StatementsNode (location: (1,0)-(1,6))
|
||||||
|
└── body: (length: 1)
|
||||||
|
└── @ StringNode (location: (1,0)-(1,6))
|
||||||
|
├── flags: ∅
|
||||||
|
├── opening_loc: (1,0)-(1,6) = "<<TEXT"
|
||||||
|
├── content_loc: (2,0)-(2,0) = ""
|
||||||
|
├── closing_loc: (2,0)-(3,0) = "TEXT\r\n"
|
||||||
|
└── unescaped: ""
|
Loading…
x
Reference in New Issue
Block a user