1 /*=============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Eric Niebler
4 Copyright (c) 2010 Thomas Heller
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #ifndef BOOST_PHOENIX_CORE_META_GRAMMAR_HPP
10 #define BOOST_PHOENIX_CORE_META_GRAMMAR_HPP
12 #include <boost/phoenix/core/limits.hpp>
13 #include <boost/mpl/deref.hpp>
14 #include <boost/phoenix/core/environment.hpp>
15 #include <boost/proto/matches.hpp>
16 #include <boost/proto/transform/call.hpp>
17 #include <boost/proto/transform/default.hpp>
19 namespace boost { namespace phoenix
21 /////////////////////////////////////////////////////////////////////////////
22 // The grammar defining valid phoenix expressions
24 : proto::switch_<meta_grammar>
26 template <typename Tag, typename Dummy = void>
28 : proto::not_<proto::_>
34 BOOST_PROTO_TRANSFORM(evaluator)
36 template <typename Expr, typename State, typename Data>
38 : proto::transform_impl<Expr, State, Data>
40 typedef meta_grammar::impl<Expr, State, Data> what;
42 typedef typename what::result_type result_type;
44 result_type operator()(
45 typename impl::expr_param e
46 , typename impl::state_param s
47 , typename impl::data_param d
50 return what()(e, s, d);
54 template <typename Expr, typename State>
55 struct impl<Expr, State, proto::empty_env>
56 : proto::transform_impl<Expr, State, proto::empty_env>
61 , typename result_of::env<State>::type
62 , typename result_of::actions<State>::type
66 typedef typename what::result_type result_type;
68 result_type operator()(
69 typename impl::expr_param e
70 , typename impl::state_param s
71 , typename impl::data_param
74 return what()(e, phoenix::env(s), actions(s));
78 template <typename Expr, typename State>
79 struct impl<Expr, State, unused>
80 : proto::transform_impl<Expr, State, unused>
85 , typename result_of::env<State>::type
86 , typename result_of::actions<State>::type
90 typedef typename what::result_type result_type;
92 result_type operator()(
93 typename impl::expr_param e
94 , typename impl::state_param s
95 , typename impl::data_param
98 return what()(e, phoenix::env(s), actions(s));
103 /////////////////////////////////////////////////////////////////////////////
104 // Set of default actions. Extend this whenever you add a new phoenix
106 struct default_actions
108 template <typename Rule, typename Dummy = void>
110 : proto::_default<meta_grammar>
114 template <typename Rule, typename Dummy = void>
116 : proto::when<Rule, proto::external_transform>
121 template <typename Expr, typename Context>
123 : boost::result_of< ::boost::phoenix::evaluator(Expr, Context)>
127 /////////////////////////////////////////////////////////////////////////////
128 // A function we can call to evaluate our expression
129 template <typename Expr, typename Context>
131 typename meta_grammar::template impl<
133 , typename result_of::env<Context const&>::type
134 , typename result_of::actions<Context const&>::type
136 eval(Expr const& expr, Context const & ctx)
138 static evaluator const e = {};
142 template <typename Expr, typename Context>
144 typename meta_grammar::template impl<
146 , typename result_of::env<Context const&>::type
147 , typename result_of::actions<Context const&>::type
149 eval(Expr & expr, Context const & ctx)
151 static evaluator const e = {};