From 5c86b6dfc4a5c74dad9f83a08d08b4536632cda1 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 22 Aug 2014 06:13:17 -0700 Subject: Set PL_expect only once after curly subscripts When curly subscripts are parsed, the lexer (toke.c:yylex) notes that the value of PL_expect needs to be set to XSTATE (expecting a state- ment) after the final brace. When the final brace is encountered, PL_expect is set to that recorded value. But then the parser (perly.y) sets it to XOPERATOR immediately thereafter. This approach requires a plethora of identical statements in perly.y. If we just set PL_expect to the right value to begin with, we can avoid all those assignments. --- perly.y | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'perly.y') diff --git a/perly.y b/perly.y index e3df8319dc..e2f934f4d2 100644 --- a/perly.y +++ b/perly.y @@ -680,9 +680,7 @@ method : METHOD subscripted: gelem '{' expr ';' '}' /* *main::{something} */ /* In this and all the hash accessors, ';' is * provided by the tokeniser */ - { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); - PL_parser->expect = XOPERATOR; - } + { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); } | scalar '[' expr ']' /* $array[$element] */ { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } @@ -698,20 +696,15 @@ subscripted: gelem '{' expr ';' '}' /* *main::{something} */ } | scalar '{' expr ';' '}' /* $foo{bar();} */ { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); - PL_parser->expect = XOPERATOR; } | term ARROW '{' expr ';' '}' /* somehref->{bar();} */ { $$ = newBINOP(OP_HELEM, 0, ref(newHVREF($1),OP_RV2HV), - jmaybe($4)); - PL_parser->expect = XOPERATOR; - } + jmaybe($4)); } | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */ { $$ = newBINOP(OP_HELEM, 0, ref(newHVREF($1),OP_RV2HV), - jmaybe($3)); - PL_parser->expect = XOPERATOR; - } + jmaybe($3)); } | term ARROW '(' ')' /* $subref->() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar($1))); } @@ -886,7 +879,6 @@ term : termbinop if ($$ && $1) $$->op_private |= $1->op_private & OPpSLICEWARNING; - PL_parser->expect = XOPERATOR; } | kvslice '{' expr ';' '}' /* %hash{@keys} */ { $$ = op_prepend_elem(OP_KVHSLICE, @@ -897,7 +889,6 @@ term : termbinop if ($$ && $1) $$->op_private |= $1->op_private & OPpSLICEWARNING; - PL_parser->expect = XOPERATOR; } | THING %prec '(' { $$ = $1; } -- cgit v1.2.1