Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-20 16:36:14

Maurizio Vitale wrote:
> Eric Niebler <eric_at_[hidden]> writes:
>> There are cases where this approach doesn't work, however. For example,
>> in xpressive, there is a repeat<>() function, for repeating
>> sub-expressions. For instance:
>> repeat<3,6>('a')
> I've taken a look at repeat and the other primitives and tags are of the
> form:
> template<int V> struct a_tag { typedef mpl::int_<V> type }
> from the tag names it seems like they're not intended to be used in pattern
> matching, but rather provide an already decoded "action" to be performed.
> For instance the tag for repeat is called generic_quant_tag and doesn't
> brings 'repeat' to mind.

Don't try to read too much into xpressive's use of proto. I began work
on xpressive in 2003. Proto evolved much later, and didn't get grammars
and transforms until last November. So xpressive doesn't isn't always a
paragon of how to use proto, although I try.

A tag is a pure compile-time encoding of the operation performed at a
node in the expression tree. It can be anything, really.

> Would be a pattern like the following be valid?
> proto::unary_expr<generic_quant_tag<3,proto::_>, proto::_>

No. Proto::matches<> doesn't do lambda-style matching on tag types, the
way it does for terminal types. It wouldn't be hard to do, but it would
make proto::matches<> much slower, for little benefit.

What xpressive does instead is something like:

     proto::if_< is_quant_tag< proto::tag_of< mpl::_ > > >
   , proto::unary_expr< proto::_, XpressiveGrammar >

And then I can test for generic_quant_tag<> in the is_quant_tag<> trait.
It's a hack, but it works.

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at