File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed
src/main/java/org/truffleruby/parser/lexer Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -115,21 +115,17 @@ public int parseString(RubyLexer lexer) {
115
115
if ((flags & STR_FUNC_EXPAND ) == 0 ) {
116
116
// heredocs without string interpolation
117
117
118
- // TODO what's in lbuf?
119
118
do { // iterate on lines, while end marker not found
120
- Rope lbuf = lexer .lexb ;
119
+ final Rope lbuf = lexer .lexb ;
121
120
int pend = lexer .lex_pend ;
122
121
123
- // Adjust pend so that it doesn't cover the final newline, excepted if the line
124
- // only has a single \n, or has both \n and \r - in which case a single \n wil be included.
125
- // TODO: this logic is insane - why is it necessary? - can it be refactored?
126
- if (pend > p ) {
122
+ // Remove trailing newline, it will be appended later in normalized form (single \n).
123
+ if (pend > 0 ) {
127
124
switch (lexer .p (pend - 1 )) {
128
125
case '\n' :
129
126
pend --;
130
- if (pend == p || lexer .p (pend - 1 ) == '\r' ) {
131
- pend ++;
132
- break ;
127
+ if (pend > 0 && lexer .p (pend - 1 ) == '\r' ) {
128
+ pend --;
133
129
}
134
130
break ;
135
131
case '\r' :
@@ -156,10 +152,8 @@ public int parseString(RubyLexer lexer) {
156
152
str = builder ;
157
153
}
158
154
159
- // if the newline wasn't included in the append, add it now
160
- if (pend < lexer .lex_pend ) {
161
- str .append ('\n' );
162
- }
155
+ // append the newline that we removed earlier
156
+ str .append ('\n' );
163
157
lexer .lex_goto_eol ();
164
158
165
159
if (lexer .getHeredocIndent () > 0 ) {
You can’t perform that action at this time.
0 commit comments