diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-12-28 17:03:52 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-28 17:03:52 +0900 |
| commit | 9b501ab5075d123235ebf8521e8b92356f306684 (patch) | |
| tree | 73e1df49b162cf9d9e29e53ffce299e9110f6d7b /mrbgems/mruby-compiler/core/parse.y | |
| parent | 6d98ae57f226da08ab374fb6347ddced7dea8b0e (diff) | |
| parent | 3a2ff9824efc5bfc9c65368f2f323ab0885e4eca (diff) | |
| download | mruby-9b501ab5075d123235ebf8521e8b92356f306684.tar.gz mruby-9b501ab5075d123235ebf8521e8b92356f306684.zip | |
Merge pull request #5247 from SeekingMeaning/squiggly-fix
Fix for empty lines in squiggly heredocs
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 9615ea7ca..da03598b1 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -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; } } |
