summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-29 12:21:52 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-29 12:21:52 +0000
commitba02d4b03bf536b24786f5b5982a08b44cf9d427 (patch)
treecd5e67c0be07e282b14e76987f0fbc0633ca4396 /parse.y
parent2110125b43fca50e532c27a009362009f8522663 (diff)
merge revision(s) 53398: [Backport #11871]
* 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/branches/ruby_2_3@54398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y53
1 files changed, 35 insertions, 18 deletions
diff --git a/parse.y b/parse.y
index 1d10f167c7..68b3219a9f 100644
--- a/parse.y
+++ b/parse.y
@@ -6210,6 +6210,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)
@@ -6239,24 +6265,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) {
@@ -6876,6 +6885,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