diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-09-16 09:44:34 -0700 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2013-10-05 14:20:10 -0400 |
commit | cc624add4b00fb447b7fbbd045a9980d27c180e2 (patch) | |
tree | b715bb016205c8a2a44bc08f2ba1e721f6bae6af /parser.h | |
parent | 158beccad252a25c107551be283bdc27e2729d29 (diff) | |
download | perl-cc624add4b00fb447b7fbbd045a9980d27c180e2.tar.gz |
Allow ->@ ->$ interpolation under postderef_qq feature
This turned out to be tricky. Normally @ at the beginning of the
interpolated code signals to the lexer to emit ‘join($",’ immediately.
With "$_->@*" we would have to retract the $ _ -> tokens upon encoun-
tering @*, which we obviously cannot do.
Waiting until we reach the end of the interpolated text before emit-
ting anything could not work either, as it may contain BEGIN blocks
that affect the way part of the interpolated code is parsed.
So what we do is introduce an egregious or clever hack, depending on
how you look at it.
Normally, the lexer turns "@foo" into:
stringify ( join ( $ " , @ foo ) )
(The " is a WORD token, representing a variable name.)
"$_" becomes:
stringify ( $ _ )
We can turn "$_->@*" into:
stringify ( $ _ -> @ * POSTJOIN )
Where POSTJOIN is a new lexer token with special handling that creates
a join op just the way join($", ...) does.
To make "foo$_->@*bar" work as well, we have to make POSTJOIN have
precedence just below ->, so that
stringify ( "foo" . $ _ -> @ * POSTJOIN . "bar" )
(what the parser sees) is equivalent to:
stringify ( "foo" . ( $ _ -> @ * POSTJOIN ) . "bar" )
Diffstat (limited to 'parser.h')
-rw-r--r-- | parser.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -54,7 +54,8 @@ typedef struct yy_parser { char *lex_brackstack;/* what kind of brackets to pop */ char *lex_casestack; /* what kind of case mods in effect */ U8 lex_defer; /* state after determined token */ - bool lex_dojoin; /* doing an array interpolation */ + U8 lex_dojoin; /* doing an array interpolation + 1 = @{...} 2 = ->@ */ U8 lex_expect; /* expect after determined token */ U8 expect; /* how to interpret ambiguous tokens */ I32 lex_formbrack; /* bracket count at outer format level */ |