Raku / nqp

NQP
Other
336 stars 131 forks source link

implement :temp for grammars #104

Open timo opened 11 years ago

timo commented 11 years ago

stumbled upon this while trying to make something like

token pod_something {
  :my $*POD_IN_FORMATTINGCODE := $*POD_IN_FORMATTINGCODE;
  ...
}

work in order to get a proper reset for the variable in case of backtracking etc.

The current workaround seems to be to do

:my $*FOO := nqp::getlexdyn('$*FOO');

but it would be much nicer to be able to write

:temp $*FOO;
arnsholt commented 10 years ago

Some notes on this. Per @pmichaud at http://irclog.perlgeek.de/perl6/2013-10-08#i_7687034 NQP will need temp, or at least :temp since STD relies on it.

Given that we handle :my in grammars by calling into the main LANG's statement rule, I think it'd make sense to implement temp in general code and do the same for :temp. OTOH, Rakudo doesn't support :temp in grammars, since it's not a declarator but a prefix operator.

Also implementation-wise, Rakudo's implementation of temp relies on the LEAVE phaser, which means that if we want to copy that implementation, we also have to implement phasers.