mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fix for empty lines in squiggly heredocs
This commit is contained in:
@@ -1362,26 +1362,29 @@ heredoc_end(parser_state *p)
|
||||
node *pair = list->car->cdr;
|
||||
const char *str = (char*)pair->car;
|
||||
size_t len = (size_t)pair->cdr;
|
||||
if (counting) {
|
||||
list2 = push(list2, pair);
|
||||
}
|
||||
mrb_bool check = counting;
|
||||
mrb_bool empty = TRUE;
|
||||
mrb_bool newline = FALSE;
|
||||
size_t spaces = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (counting) {
|
||||
if (ISSPACE(str[i])) {
|
||||
++spaces;
|
||||
}
|
||||
else {
|
||||
counting = FALSE;
|
||||
if (indent == -1 || spaces < indent) {
|
||||
indent = spaces;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (str[i] == '\n') {
|
||||
counting = TRUE;
|
||||
newline = TRUE;
|
||||
break;
|
||||
}
|
||||
if (ISSPACE(str[i])) {
|
||||
if (counting)
|
||||
++spaces;
|
||||
}
|
||||
else {
|
||||
counting = FALSE;
|
||||
empty = FALSE;
|
||||
}
|
||||
}
|
||||
if (check) {
|
||||
if ((indent == -1 || spaces < indent) && (!empty || !newline))
|
||||
indent = spaces;
|
||||
list2 = push(list2, cons((node*)spaces, pair));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1391,11 +1394,15 @@ heredoc_end(parser_state *p)
|
||||
}
|
||||
if (indent > 0) {
|
||||
while (list2) {
|
||||
node *pair = list2->car;
|
||||
const char *str = (char*)pair->car;
|
||||
size_t len = (size_t)pair->cdr;
|
||||
pair->car = (node*)(str + indent);
|
||||
pair->cdr = (node*)(len - indent);
|
||||
node *n = list2->car;
|
||||
size_t spaces = (size_t)n->car;
|
||||
if (spaces >= indent) {
|
||||
node *pair = n->cdr;
|
||||
const char *str = (char*)pair->car;
|
||||
size_t len = (size_t)pair->cdr;
|
||||
pair->car = (node*)(str + indent);
|
||||
pair->cdr = (node*)(len - indent);
|
||||
}
|
||||
list2 = list2->cdr;
|
||||
}
|
||||
}
|
||||
|
||||
+1025
-1018
File diff suppressed because it is too large
Load Diff
@@ -181,6 +181,12 @@ QQ2
|
||||
UUU2
|
||||
u#{3}u
|
||||
UUU3
|
||||
v = <<~VVV
|
||||
|
||||
\tvvv
|
||||
\t\t
|
||||
\t#{123}
|
||||
VVV
|
||||
|
||||
w = %W( 1 #{<<WWW} 3
|
||||
www
|
||||
@@ -221,6 +227,7 @@ ZZZ
|
||||
assert_equal "sss\n sss\n", s
|
||||
assert_equal "ttt\n ttt\n", t
|
||||
assert_equal ["u1u\n", "u2u\n", "u\#{3}u\n"], u
|
||||
assert_equal "\nvvv\n\t\n123\n", v
|
||||
assert_equal ["1", "www\n", "3", "4", "5"], w
|
||||
assert_equal [1, "foo 222 333\n 444\n5\n bar\n6\n", 9], x
|
||||
assert_equal "", z
|
||||
|
||||
Reference in New Issue
Block a user