This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: For plugins, don’t set PL_expect if PL_nexttoke
authorFather Chrysostomos <sprout@cpan.org>
Sat, 23 Aug 2014 01:11:23 +0000 (18:11 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 25 Aug 2014 02:02:57 +0000 (19:02 -0700)
When a parsing plugin finishes parsing its stuff, the lexer may have
emitted one more token than the construct it was parsing (if the
plugin called parsing API functions like parse_fullstmt).  In such
cases, yyunlex has pushed that token on to the pending token stack
with force_next.

When the lexer is about to emit the plugin’s parsed statement or
expression, if there is a pending token, then it does not need to set
PL_expect, since the previous value will be restored anyway when the
pending token is emitted.

The next commit will disable that save-and-restore mechanism for
PL_expect, so we must not assign to it here.

toke.c

diff --git a/toke.c b/toke.c
index f3a493c..7f89e54 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -6318,12 +6318,12 @@ Perl_yylex(pTHX)
            } else if (result == KEYWORD_PLUGIN_STMT) {
                pl_yylval.opval = o;
                CLINE;
-               PL_expect = XSTATE;
+               if (!PL_nexttoke) PL_expect = XSTATE;
                return REPORT(PLUGSTMT);
            } else if (result == KEYWORD_PLUGIN_EXPR) {
                pl_yylval.opval = o;
                CLINE;
-               PL_expect = XOPERATOR;
+               if (!PL_nexttoke) PL_expect = XOPERATOR;
                return REPORT(PLUGEXPR);
            } else {
                Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",