diff options
author | Father Chrysostomos <sprout@cpan.org> | 2015-01-08 18:49:32 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2015-01-08 19:00:57 -0800 |
commit | 9b6b7be8acad62650aa5c229e89fad6706c8a0b0 (patch) | |
tree | 07c815d34c2af0b830e9741bfff73d78f9fb74a9 /perly.y | |
parent | cc5af3775649fc00e4d4e74d41dcad591b1fa122 (diff) | |
download | perl-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.y | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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 |