diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-31 20:06:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-31 20:06:22 +0000 |
commit | b1796737cf097ff7dc68b12ebb6d86a9528c95be (patch) | |
tree | 51293019c4674da8db80696f7bf9a38b932a5517 /parse.y | |
parent | d6c769a5fe6ba33ee5950e18f8cbbebea742e1b1 (diff) | |
download | ruby-b1796737cf097ff7dc68b12ebb6d86a9528c95be.tar.gz |
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
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 53 |
1 files changed, 35 insertions, 18 deletions
@@ -6215,6 +6215,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, rb_encoding **encp) @@ -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 |