|
Boost Users : |
Subject: Re: [Boost-users] [Proto] Processing Lists
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-02-23 01:15:32
On Mon, Feb 22, 2010 at 3:29 AM, David Greene <greened_at_[hidden]> wrote:
> I want to process a list that looks something like this:
>
> struct List : or_<
> comma<
> List,
> Item
> >,
> Item
>> {};
>
> But rather than processing each item separately, I want to pass a fusion (or
> some other) sequence to a semantic action:
>
> when<
> List,
> SomeAction(...)
>> {};
>
> Ideally the argument to SomeAction would be a fusion sequence but I don't
> know how to produce one. This doesn't work:
>
> when<
> List,
> SomeAction(flatten(_))
>> {};
>
> because flatten is not a transform. I don't want to use fold_tree because I
> don't want to actually fold the sequence. SomeAction is something like this:
>
> struct SomeAction : callable {
> template<typename Seq>
> void operator()(Seq range) {
> typedef ... iterator;
>
> // Is this legal for fusion sequences?
> for(iterator i = begin(range), iend = end(range);
> i != iend;
> i = next(i)) {
> ...
> }
> }
> }
>
> Is there a way to do this?
>
> On a related note, I know I can use varag<> to match a function call
> expression with an arbitrary number of operands and invoke a transform
> on each operand. But how would I generate a fusion sequence of all
> the operands? In other words, with:
>
> proto::function< X, proto::vararg<Y> >
>
> how do I talk about the vararg<> part in a semantic action? CalculatorGrammar
> has a use of vararg but it uses fold<> to process it. I don't want to fold a
> sequence, I want to pass it to a transform.
I had something like
struct foo_tostr
: proto::or_ <proto::when<proto::function<proto::terminal<foo>,
proto::vararg<proto::terminal<var> > >,
proto::fold<proto::functional::pop_front(proto::_expr), string(),
str_plus(proto::_state, var_tostr)> > > {};
to convert the operands of a function call expression to a string. I
believe proto::_expr is itself a fusion sequence. I could use
fusion::at_c<N>(proto::_expr) to access the elements.
proto::functional::pop_front(proto::_expr) is like lisp cdr, gives you
everything except the first element of the sequence.
Manjunath
> Thanks!
>
> -Dave
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net