summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2015-01-08 18:49:32 -0800
committerFather Chrysostomos <sprout@cpan.org>2015-01-08 19:00:57 -0800
commit9b6b7be8acad62650aa5c229e89fad6706c8a0b0 (patch)
tree07c815d34c2af0b830e9741bfff73d78f9fb74a9 /perly.y
parentcc5af3775649fc00e4d4e74d41dcad591b1fa122 (diff)
downloadperl-9b6b7be8acad62650aa5c229e89fad6706c8a0b0.tar.gz
Simplify s/// and tr/// parsing logic
These two operators were being translated into subst("","") and tr("","") by the lexer. Then pmruntime in op.c would take apart the resulting list op. Instead of constructing a list op only to take it apart again, feed the replacement part to pmruntime separately. We can achieve this by introducing a new token ('/') that the parser rec- ognizes as introducing a replacement. If we had followed this approach to begin with, then bug #123542 would never have happened. (Actually, it seems the parser did know about the replacement part to begin with, but it changed in perl-5.8.0-4047-g131b3ad to fix some overloading problems.)
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y12
1 files changed, 9 insertions, 3 deletions
diff --git a/perly.y b/perly.y
index e575b70e02..6b362c9809 100644
--- a/perly.y
+++ b/perly.y
@@ -70,7 +70,7 @@
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
%type <opval> sliceme kvslice gelem
%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
-%type <opval> optlistexpr optexpr indirob listop method
+%type <opval> optlistexpr optexpr optrepl indirob listop method
%type <opval> formname subname proto optsubbody cont my_scalar my_var
%type <opval> refgen_topic formblock
%type <opval> subattrlist myattrlist myattrterm myterm
@@ -996,8 +996,8 @@ term : termbinop
} else
$<ival>$ = 0;
}
- '(' listexpr ')'
- { $$ = pmruntime($1, $4, 1, $<ival>2); }
+ '(' listexpr optrepl ')'
+ { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
| WORD
| listop
| YADAYADA
@@ -1042,6 +1042,12 @@ optexpr: /* NULL */
{ $$ = $1; }
;
+optrepl: /* NULL */
+ { $$ = (OP*)NULL; }
+ | '/' expr
+ { $$ = $2; }
+ ;
+
/* A little bit of trickery to make "for my $foo (@bar)" actually be
lexical */
my_scalar: scalar