File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
lib/prism/translation/parser Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -2040,6 +2040,13 @@ def visit_block(call, block)
2040
2040
end
2041
2041
end
2042
2042
2043
+ # The parser gem automatically converts \r\n to \n, meaning our offsets
2044
+ # need to be adjusted to always subtract 1 from the length.
2045
+ def chomped_bytesize ( line )
2046
+ chomped = line . chomp
2047
+ chomped . bytesize + ( chomped == line ? 0 : 1 )
2048
+ end
2049
+
2043
2050
# Visit a heredoc that can be either a string or an xstring.
2044
2051
def visit_heredoc ( node )
2045
2052
children = Array . new
@@ -2066,14 +2073,14 @@ def visit_heredoc(node)
2066
2073
if node . opening . end_with? ( "'" )
2067
2074
escaped . each do |line |
2068
2075
escaped_lengths << line . bytesize
2069
- normalized_lengths << ( line . chomp . bytesize + 1 )
2076
+ normalized_lengths << chomped_bytesize ( line )
2070
2077
end
2071
2078
else
2072
2079
escaped
2073
2080
. chunk_while { |before , after | before . match? ( /(?<!\\ )\\ \r ?\n $/ ) }
2074
2081
. each do |lines |
2075
2082
escaped_lengths << lines . sum ( &:bytesize )
2076
- normalized_lengths << lines . sum { |line | line . chomp . bytesize + 1 }
2083
+ normalized_lengths << lines . sum { |line | chomped_bytesize ( line ) }
2077
2084
end
2078
2085
end
2079
2086
Original file line number Diff line number Diff line change @@ -59,7 +59,6 @@ class ParserTest < TestCase
59
59
# These files are either failing to parse or failing to translate, so we'll
60
60
# skip them for now.
61
61
skip_all = skip_incorrect | [
62
- "dash_heredocs.txt" ,
63
62
"regex.txt" ,
64
63
"regex_char_width.txt" ,
65
64
"unescaping.txt" ,
@@ -86,6 +85,7 @@ class ParserTest < TestCase
86
85
# output expected by the parser gem, so we'll skip them for now.
87
86
skip_tokens = [
88
87
"comments.txt" ,
88
+ "dash_heredocs.txt" ,
89
89
"dos_endings.txt" ,
90
90
"embdoc_no_newline_at_end.txt" ,
91
91
"heredoc_with_comment.txt" ,
You can’t perform that action at this time.
0 commit comments