Skip to content

Commit

Permalink
parse.y: broke the terminator condition down
Browse files Browse the repository at this point in the history
* parse.y (here_document): broke the terminator condition down
  into each piece, the positional condition, resetting the
  dedented here-document indentation, and matching identifier.
  suppress a false warning by icc.
  • Loading branch information
nobu committed May 26, 2019
1 parent 4f2a7b8 commit a43c637
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 11 additions & 7 deletions parse.y
Expand Up @@ -7201,13 +7201,17 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
return 0;
}
bol = was_bol(p);
/* `heredoc_line_indent == -1` means
* - "after an interpolation in the same line", or
* - "in a continuing line"
*/
if (bol &&
(p->heredoc_line_indent != -1 || (p->heredoc_line_indent = 0)) &&
whole_match_p(p, eos, len, indent)) {
if (!bol) {
/* not beginning of line, cannot be the terminater */
}
else if (p->heredoc_line_indent == -1) {
/* `heredoc_line_indent == -1` means
* - "after an interpolation in the same line", or
* - "in a continuing line"
*/
p->heredoc_line_indent = 0;
}
else if (whole_match_p(p, eos, len, indent)) {
dispatch_heredoc_end(p);
heredoc_restore(p, &p->lex.strterm->u.heredoc);
p->lex.strterm = 0;
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_syntax.rb
Expand Up @@ -753,6 +753,8 @@ def test_dedented_heredoc_continued_line
\
TEXT
end;

assert_equal(" TEXT\n", eval("<<~eos\n" " \\\n" "TEXT\n" "eos\n"))
end

def test_lineno_after_heredoc
Expand Down

0 comments on commit a43c637

Please sign in to comment.