Subject: Re: [proto] Visitor Design Pattern
From: Eric Niebler (eric_at_[hidden])
Date: 2010-10-25 20:44:42
On 10/25/2010 4:44 PM, Joel de Guzman wrote:
> On 10/26/2010 4:30 AM, Eric Niebler wrote:
>> Voila! The implementation is trivial: one specialization of proto::when
>> on the new (incomplete) proto::external type. God, why didn't I think of
>> this sooner?
>> The naming issue goes away completely. There is no fancy new proto
>> transform to be named. Also, proto::named_rule goes away, too.
>> One potential further simplification would be to give users a nicer way
>> to map rules to actions. I'll think about it.
> This is awesome, Eric! I thought we had a winner. Now you doubled
> the win! :-) Don't stop! ;-)
I just committed this to trunk. I also added an "action_map" class that
makes it pretty easy and intuitive to define action parameters. The
previous example becomes:
proto::when< int_terminal, proto::external >
, proto::when< char_terminal, proto::external >
proto::plus< my_grammar, my_grammar >
, proto::fold< _, int(), my_grammar >
, proto::when<char_terminal, print(proto::_value)>
It uses mpl::map under the hood for optimized look-up time on the rule
type. Of course, using action_map makes your actions non-extensible, so
this feature is not interesting for Phoenix. You can still do it the
other way with a nested "when" template that you can specialize on rules.
I might rename "action_map" to "transform_map" or even just
"transforms". I think this is the only place in proto where transforms
are referred to as actions. Opinions?
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Proto list run by eric at boostpro.com