On 1/7/2010 12:54 PM, David A. Greene wrote:
On Tuesday 05 January 2010 03:47:39 Eric Niebler wrote:
In your code, you have:
#ifdef NO_SPECIALIZATION template<> struct ConstructStatementGrammarCases::case_<boost::proto::tag::subscript>
I'm sure if you change your ifdef to ifndef, or just remove the PP gunk, you'll see that it works.
<brownpaperbag> Oh, bother. </brownpaperbag>
Haha!
It works now. And I think I grok proto!
Welcome to the club. Your propeller hat should arrive in a few days. ;-)
I've successfully added more statement-type rules and it works great.
A couple of questions:
Is there any advantage to doing:
// An if_ "operator" template<typename Expr> typename boost::proto::result_of::make_expr< boost::proto::tag::function, Domain, keyword::if_, Expr>::type if_(Expr const&expr) { return boost::proto::make_expr<boost::proto::tag::function, Domain>( keyword::if_(), expr); }
over:
typedef Wrapper<boost::proto::terminal<keyword::if_>::type> IfTerminal;
// An if_ "operator." namespace { const IfTerminal if_ = {{}}; }
and letting proto take care of creating the function expression? Perhaps the former has one or two less template instantiations but the latter is certainly easier to maintain.
Joel F, already answered this one, and his answer is right. The two formulations are functionally equivalent. The function compiles faster, though.
Also, we can get something akin to synthesized attributes with the grammar semantics actions:
struct case_ : boost::proto::when< IfRule, ConstructBinary<If>(ConstructExpressionGrammar(boost::proto::_right(boost::proto::_left)), ConstructStatementGrammar(boost::proto::_right))> {};
where Construct*Grammar is a transform grammar that returns some result (so it's a transform too, right?).
Yes, all Proto _grammars_ are also _primitive transforms_ and can be used as you are using them above to compose _callable transforms_. (Check the glossary for the meaning of those terms.)
Is there any way to get something akin to inherited attributes that one can pass down the expression tree?
Not exactly sure what you are asking. You mean you want to pass stuff around to all the transforms? All _primitive transforms_ are automatically passed a state and a data parameter. If you don't specify them (you haven't), dummies get filled in for you. You can use one of those to pass around any extra information your transforms need.
Finally, I think the wrapper metafunction problem I posted about is still an issue, though I seem to be getting by without the dummy template argument to do the ADL trick.
Sorry, which issue was that? -- Eric Niebler BoostPro Computing http://www.boostpro.com