
On 06/01/2007 03:34 PM, Maurizio Vitale wrote:
Larry Evans <cppljevans@cox-internet.com> writes: [snip]
struct xmpl_context { explicit xmpl_context(unsigned& a_indent) : indent(a_indent) { }
template<typename Expr, long Arity = Expr::arity::value> struct eval {
typedef void result_type; result_type operator()(Expr &expr, xmpl_context &ctx) const { typedef proto::tagof<Expr>::type tag_type; const char*tag_name=std::typeid(tag_type).name() std::cout<<std::setw(indent) <<""<<tag_name<<".get_instance=" <<expr.get_instance()<<"\n"; indent+=2; for(long ichild=0; ichild<Arity; ++ichild) { proto::eval(proto::arg_c<Expr,ichild>(expr), *this); } indent-=2; } };
private: unsigned& indent;
};
I noticed in boost/xpressive/proto/fusion.hpp there's children templates, but they don't look like they'd help. How do I do what's implied by the above for loop?
It seems to me you're duplicating what display_expr does (in debug.hpp), but if the question is more general and you need to do something else you can look at proto::transform::fold (or fold_to_list if you need more persistence).
You're almost right about duplicating display_expr; however, my purpose was to see if I could access and printout the extension, xmpl_delta that was shown in my earlier post. Of course this xmpl_delta is not my ultimate goal, but, hopefully, it will show me, at least partly, how to achieve that ultimate goal. (BTW, that goal is the calculation of first and follow attributes of the grammar subexpressions as done here: http://svn.boost.org/trac/boost/browser/sandbox/boost/grammar_pipeline/eff/p... IOW, xmpl_delta would be replaced by the lookahead_attributes found on line 89 of productions.hpp. ). BTW, I have made some progress in solving the problem. It looks like: struct xmpl_context { explicit xmpl_context(unsigned& a_indent) : indent(a_indent) { } template<typename Expr, long Arity = Expr::arity::value> struct eval { struct eval_child_i { Expr const& my_parent; xmpl_context& my_context; eval_child_i ( Expr const& a_parent , xmpl_context& a_context ) : my_parent(a_parent) , my_context(a_context) {} template<long Index> void operator()(mpl::integral_c<long,Index>&) { proto::eval(proto::arg_c<Expr,Index>(my_parent),my_context); } }; typedef unsigned result_type; result_type operator()(Expr const &expr, xmpl_context &ctx) { typedef typename proto::tag_of<Expr>::type tag_type; const char*tag_name=typeid(tag_type).name(); std::cout<<std::setw(ctx.indent)<<""<<tag_name<<".get_instance="<<expr.get_instance()<<"\n"; ctx.indent+=2; typedef typename mpl::range_c<long,0,Arity>::type indices_type; eval_child_i a_eval_child(expr,ctx); mpl::for_each<indices_type>(a_eval_child); ctx.indent-=2; return ctx.indent; } }; private: unsigned& indent; }; However, I'm still getting compile errors: extend_transform_xmpl.cpp:142: instantiated from here extend_transform_xmpl.cpp:59: error: no matching function for call to 'arg_c(const xmpl_expression<boost::proto::expr<boost::proto::tag::terminal, boost::proto::args1<arg_id<1u> >, 1l> >&)' and still investigating. Thanks for the suggestions. -regards, Larry [snip]