diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-09-07 17:43:26 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-09-07 18:34:37 -0700 |
commit | b42366d4c37f0739fb5f9105feb416811057931a (patch) | |
tree | dd2bb6e8413aece490fb1b6e6a299a5b6f8c7e65 /t | |
parent | a046df752d35f41083b1946a2f0e23d234df233a (diff) | |
download | perl-b42366d4c37f0739fb5f9105feb416811057931a.tar.gz |
Respect #line directives in here-docs
#line directives in here-docs used to be ignored after the heredoc:
<<END
${
#line 27
print __LINE__,"\n" # prints 27
}
END
; print __LINE__, "\n"; # prints 7
This commit changes that by recording in PL_multi_end the end of
the here-doc (more precisely, the last line of the body, before the
terminator) during the initial parse to find the terminator. When
the body is parsed for double-quotish stuff, at the very end (in
sublex_done) the last line number is compared with the one recorded.
Any differences are applied to the current ‘herelines’ value, which
records how many line numbers need to be skipped when the line ending
after the here-doc marked (<<END) is reached.
It conflicts with a line number workaround in op.c, which hasn’t done
anything since I accidentally disabled it in 5.18.
Added in 0244c3a40, this code set the current line number to the end
of the here-doc when creating the substitution op for s//<<foo/e.
Before that, since the line number was localised to the lexing scope,
the new line number set by the here-doc would be undone when the s///
finished, throwing off all subsequent line numbers.
Commit 83944c0156 solved the problem of the line number for code after
the here-doc marker having the wrong line number (because the here-doc
parser would increase the line number by the number of lines in the
here-doc body straightaway). It introduced the ‘herelines’ value,
recording how many lines the here-doc body contained, but without
updating the line number yet, so that code after the <<marker would
have the right line, but the next \n would increment the line number
by herelines+1. That accidentally stopped PL_multi_end from having
the right value, disabling the line number code in op.c. But the
other changes rendered that code unnecessary.
Diffstat (limited to 't')
-rw-r--r-- | t/comp/parser.t | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/t/comp/parser.t b/t/comp/parser.t index a881d4cda8..569ecd790e 100644 --- a/t/comp/parser.t +++ b/t/comp/parser.t @@ -8,7 +8,7 @@ BEGIN { chdir 't'; } -print "1..165\n"; +print "1..166\n"; sub failed { my ($got, $expected, $name) = @_; @@ -619,5 +619,12 @@ check_line(54, 'line number after qq"${#line}"'); " ${check_line(25, 'line number inside qq/<newline>${...}/')}"; +<<"END"; +${; +#line 625 +} +END +check_line(627, 'line number after heredoc containing #line'); + __END__ # Don't add new tests HERE. See note above |