toke.c:S_scan_heredoc: Put stream-based parser in else block
authorFather Chrysostomos <sprout@cpan.org>
Wed, 29 Aug 2012 15:41:41 +0000 (08:41 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 01:18:07 +0000 (18:18 -0700)
We currently have the code laid out like this:

    if (peek) {
        ... peek inside the parent linestr buffer
    }
    else if (eval) {
        ... grab the heredoc body from linestr ...
    }
    else
        start with an empty string for the heredoc body

    ... parse the body of the heredoc from the input stream ...

The final bit is inside a while loop whose condition is never true
after either of the first two branches of the if/else has executed.
But the code is very hard to read, and it is difficult to fix bugs, as
code cannot be added before the while loop, and the while loop condi-
tion cannot change, without affecting heredocs in string eval.

So put the final parser inside the else.  Future commits will
depend on this.

toke.c

diff --git a/toke.c b/toke.c
index 0a74efe..11be455 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9751,11 +9751,12 @@ S_scan_heredoc(pTHX_ register char *s)
        s = olds;
     }
     else
-      streaming:
-       sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
-    term = PL_tokenbuf[1];
-    len--;
-    while (s >= PL_bufend) {   /* multiple line string? */
+    {
+     streaming:
+      sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
+      term = PL_tokenbuf[1];
+      len--;
+      while (s >= PL_bufend) { /* multiple line string? */
 #ifdef PERL_MAD
        if (PL_madskills) {
            tstart = SvPVX(PL_linestr) + stuffstart;
@@ -9814,6 +9815,7 @@ S_scan_heredoc(pTHX_ register char *s)
            s = PL_bufend;
            sv_catsv(tmpstr,PL_linestr);
        }
+      }
     }
     s++;
 retval: