From b1796737cf097ff7dc68b12ebb6d86a9528c95be Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 31 Dec 2015 20:06:22 +0000 Subject: parse.y: single-quote indented heredoc * parse.y (parser_here_document): update indent for each line in indented here document with single-quotes. [ruby-core:72479] [Bug #11871] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 161ba02dbb..cfbef9c764 100644 --- a/parse.y +++ b/parse.y @@ -6214,6 +6214,32 @@ simple_re_meta(int c) } } +static int +parser_update_heredoc_indent(struct parser_params *parser, int c) +{ + if (heredoc_line_indent == -1) { + if (c == '\n') heredoc_line_indent = 0; + } + else { + if (c == ' ') { + heredoc_line_indent++; + return TRUE; + } + else if (c == '\t') { + int w = (heredoc_line_indent / TAB_WIDTH) + 1; + heredoc_line_indent = w * TAB_WIDTH; + return TRUE; + } + else if (c != '\n') { + if (heredoc_indent > heredoc_line_indent) { + heredoc_indent = heredoc_line_indent; + } + heredoc_line_indent = -1; + } + } + return FALSE; +} + static int parser_tokadd_string(struct parser_params *parser, int func, int term, int paren, long *nest, @@ -6244,24 +6270,7 @@ parser_tokadd_string(struct parser_params *parser, while ((c = nextc()) != -1) { if (heredoc_indent > 0) { - if (heredoc_line_indent == -1) { - if (c == '\n') heredoc_line_indent = 0; - } - else { - if (c == ' ') { - heredoc_line_indent++; - } - else if (c == '\t') { - int w = (heredoc_line_indent / TAB_WIDTH) + 1; - heredoc_line_indent = w * TAB_WIDTH; - } - else if (c != '\n') { - if (heredoc_indent > heredoc_line_indent) { - heredoc_indent = heredoc_line_indent; - } - heredoc_line_indent = -1; - } - } + parser_update_heredoc_indent(parser, c); } if (paren && c == paren) { @@ -6881,6 +6890,14 @@ parser_here_document(struct parser_params *parser, NODE *here) --pend; } } + + if (heredoc_indent > 0) { + long i = 0; + while (p + i < pend && parser_update_heredoc_indent(parser, p[i])) + i++; + heredoc_line_indent = 0; + } + if (str) rb_str_cat(str, p, pend - p); else -- cgit v1.2.3