[Merge] Here-doc parsing
I was waiting for 5.17.3 to be released, before merging my work on
padlists (which is blocking lexical subs), since I thought it would be
mean to inflict it on blead at the last minute before a release.
So, in the mean time, I decided to fix a small here-doc parsing bug,
that prevented them from occurring inside regexp code blocks.
As often happens, it turned out to be more involved than that....
I ended up writing a history of here-doc parsing, which you can find
in the commit message for
5097bf9b8d, which shows that the way they
have interacted with other quote-like operators (or other here-docs)
has changed over time in interesting ways.
While I was fixing those, I started to find other bugs. Since I was
modifying the code, I decided to try applying David Nicol’s patch that
allows a here-doc terminator with no newline after it, to avoid creat-
ing more conflicts through my changes. The patch didn’t work. And
while I was resolving what conflicts there were, I figured out a sim-
pler approach. So, instead of trying to investigate into why the
patch didn’t work, I just wrote my own version, which used less code.
Instead of working back on error to try to see whether we could have
accepted a terminator without a newline, we can just tack a newline on
the string buffer at EOF and let the rest of the code handle it the
usual way.
I continued to find more bugs as I went, till my ‘Yay, another bug!’
started to become ‘What? *Another* bug?’.
In the end:
• I fixed here-doc parsing, such that the body starts on the line fol-
lowing the <<foo marker, regardless of whether it is inside quotes,
string evals, or what have you (but see remaining bugs below). This
was contrary to the documentation, but the documentation was actu-
ally wrong half the time, so I corrected it.
• Here-doc terminators no longer require a final newline at EOF.
• You no longer get crashes with edge cases.
• Nulls in comments no longer confuse the here-doc parser.
And, finally, one bug that I fixed was not related to here-docs per
se, but got in the way. It deserves its own JAPH:
s/${s|||, \""}Just another Perl hacker,
/anything/;
print
There are still two bugs remaining:
• Here-docs whose markers occur in single-line s/// patterns where the
replacement part is multi-line or starts on a subsequent line are
still screwed.
• CR and CR LF line terminators are treated inconsistently inside and
outside of string evals.
I’ve decided to set those aside for later and merge what I’ve
done so far.