![]() |
Home | Libraries | People | FAQ | More |
BOOST_PHOENIX_DEFINE_EXPRESSION
is a macro that can be used to generate all the necessary boilerplate to
create Phoenix Expressions
BOOST_PHOENIX_DEFINE_EXPRESSION( (namespace_seq)(name) , (child_grammar0) (child_grammar1) ... )
The above macro generates the necessary code for an expression name
in namespace namespace_seq
.
The sequence of (child_grammarN)
declares how many children the expression
will have and what proto::grammar
they match.
The macro should be used at global scope. namespace_seq
shall be the sequence of namespaces under which the following symbols will
be defined:
namespace tag { struct name; } namespace expression { template <typename A0, typename A1 ... typename AN> struct name : boost::phoenix::expr< tag::name , A0 , A1 ... , AN > } namespace rule { struct name : boost::phoenix::expr< child_grammar0 , child_grammar1 ... , child_grammarN > {}; }
This macros also adds a specialization for meta_grammar::case_<tag::name>
.
#include <boost/phoenix/core/expression.hpp>
The example from the previous section can be rewritten as:
BOOST_PHOENIX_DEFINE_EXPRESSION( (plus) , (meta_grammar) // Lhs (meta_grammar) // Rhs ) template <typename Lhs, typename Rhs> typename plus<Lhs, Rhs>::type plus(Lhs const & lhs, Rhs const & rhs) { return expression::plus<Lhs, Rhs>::make(lhs, rhs); }