diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-06 14:34:25 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-08-08 12:24:49 -0700 |
commit | b27dce25d7618d1797015079eaecd1913f133d47 (patch) | |
tree | 115ad1052fbc3e1204caf4a831137471668f01ba /t | |
parent | 513b1ee2ffc66290ce706625c54422114d634f98 (diff) | |
download | perl-b27dce25d7618d1797015079eaecd1913f133d47.tar.gz |
toke.c: Fix confused interp-in-format parsing
The lexer keeps track of how many levels of brackets it is currently
in (including the = and . delimiting formats, which count as brackets)
in PL_lex_brackets.
When parsing a format, the lexer sets lex_formbrack to the form’s
bracket number. Whitespace parsing takes note of this, and avoids
reading beyond the end of the current line inside a format, unless it
is in an inner bracketed construct. So this:
format =
@
$a
+ $b
.
treats ‘ + $b’ as a literal string, which becomes the second line
of output.
But this:
format =
@
{ $a
+ $b }
.
treats the whole {...} block as the argument for the first format pic-
ture line.
For interpolating (i.e., quoted) constructs, the lexer temporarily
resets the bracket count. This is so that when it reaches the final
brace in "${...}foo()" it can parse the rest (foo()) as a constant,
rather than a sub call.
When the bracket count was reset, lex_formbrack was left as it was,
resulting in confusion:
# ok
format =
@
${; use
strict}
.
# also ok
format =
@
"${; {use
strict} }"
.
# syntax error (or crash)
format =
@
"${; use
strict }"
.
# crash
format =
@
"${ use
strict }"
.
When the bracket count is localised and reset at the start of a quoted
construct, we now do the same with lex_formbrack.
Diffstat (limited to 't')
-rw-r--r-- | t/op/write.t | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/t/op/write.t b/t/op/write.t index 2d5b0ac79a..60ae9b3426 100644 --- a/t/op/write.t +++ b/t/op/write.t @@ -58,7 +58,7 @@ for my $tref ( @NumTests ){ #--------------------------------------------------------- # number of tests in section 1 -my $bas_tests = 20; +my $bas_tests = 21; # number of tests in section 3 my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 5; @@ -278,6 +278,18 @@ write (OUT4); close OUT4 or die "Could not close: $!"; is cat('Op_write.tmp'), "1\n" and unlink_all "Op_write.tmp"; +# More LEX_INTERPNORMAL +format OUT4a= +@<<<<<<<<<<<<<<< +"${; use + strict; \'Nasdaq dropping like flies'}" +. +open OUT4a, ">Op_write.tmp" or die "Can't create Op_write.tmp"; +write (OUT4a); +close OUT4a or die "Could not close: $!"; +is cat('Op_write.tmp'), "Nasdaq dropping\n", 'skipspace inside "${...}"' + and unlink_all "Op_write.tmp"; + eval <<'EOFORMAT'; format OUT10 = @####.## @0###.## |