|
Boost : |
From: David A. Greene (greened_at_[hidden])
Date: 2007-07-07 21:01:10
On Sunday 01 July 2007 17:24, Eric Niebler wrote:
> > template<typename Expr ...>
> > struct phoenix_expr
> >
> > : proto::extends<Expr ...>
> >
> > {
> > phoenix_expr(...)
> >
> > : else_(proto::make_expr<phoenix::tag::else_>(*this))
> >
> > {}
> >
> > // ...
> >
> > proto::result_of::make_expr<
> > pheonix::tag::else_ // else is now an "operator"
> > , phoenix_expr const
> >
> > >::type const else_;
> >
> > };
> >
> > how do I match the new "else_ operator" and transform it?
>
> Well, if you use the BOOST_PROTO_DEFINE_FUNCTION_TEMPLATE macro like I
> show above, the IfElseGrammar might look like this:
>
> // matches if_(e1)[e2].else_[e3]
> struct IfElseGrammar
>
> : subscript<
>
> unary_expr<
> phoenix::tag::else_
> , subscript<
> unary_expr<
> phoenix::tag::if_
> , PhoenixBooleanGrammar
>
> , PhoenixGrammar
>
>
> , PhoenixGrammar
>
> {};
All right, that makes good sense. Now the next obvious thing to do is try
do_[e1].while_(e2). So here's my attempt:
// A do_ "operator"
boost::proto::terminal<tag::Do>::type const do_ = {{}};
// matches do[e1]
struct DoGrammar
: boost::proto::subscript<
tag::Do,
StatementGrammar
> {};
// A while_ "operator"
template<typename Expr>
struct Expression<
Expr
, typename enable_if<proto::matches<Expr, DoGrammar> >::type
>
: proto::extends<Expr, Expression<Expr>, Domain>
{
Expression()
: while_(proto::make_expr<tag::While>(*this)) {};
// Oops, don't know how to do this here
BOOST_PROTO_DEFINE_FUNCTION_TEMPLATE(
1
, while_
, Domain
, (tag::While)
, BOOST_PP_SEQ_NIL
);
};
// matches do[e1].while_(e2)
struct DoWhileGrammar
: boost::proto::unary_expr<
DoGrammar,
tag::While
> {};
Other than the fact that I don't know how to declare the while_ member
above, does this look correct?
Of course, I want to do while_(e1)[e2] as well, so there already is
BOOST_PROTO_DEFINE_FUNCTION_TEMPLATE(
1
, while_
, Domain
, (tag::While)
, BOOST_PP_SEQ_NIL
);
at namespace scope. Is there some way to reuse this in the extension of
expressions that match DoGrammar?
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk