1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2011 Thomas Heller
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM)
8 #define BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM
14 #include <boost/spirit/include/phoenix_core.hpp>
16 namespace boost { namespace spirit { namespace lex
18 ///////////////////////////////////////////////////////////////////////////
19 // The value_context is used as a noop Phoenix actor to create the
20 // placeholder '_val' (see below). It is a noop actor because it is used
21 // as a placeholder only, while it is being converted either to a
22 // value_getter (if used as a rvalue) or to a value_setter (if used as a
23 // lvalue). The conversion is achieved by specializing and overloading a
24 // couple of the Phoenix templates from the Phoenix expression composition
25 // engine (see the end of this file).
28 typedef mpl::true_ no_nullary;
30 typedef unused_type result_type;
32 template <typename Env>
35 typedef unused_type type;
38 template <typename Env>
40 eval(Env const& env) const
46 // forward declarations
48 template <typename> struct value_setter;
50 ///////////////////////////////////////////////////////////////////////////
51 // The state_context is used as a noop Phoenix actor to create the
52 // placeholder '_state' (see below). It is a noop actor because it is used
53 // as a placeholder only, while it is being converted either to a
54 // state_getter (if used as a rvalue) or to a state_setter (if used as a
55 // lvalue). The conversion is achieved by specializing and overloading a
56 // couple of the Phoenix templates from the Phoenix expression composition
57 // engine (see the end of this file).
60 typedef mpl::true_ no_nullary;
62 typedef unused_type result_type;
64 template <typename Env>
67 typedef unused_type type;
70 template <typename Env>
72 eval(Env const& env) const
78 // forward declarations
80 template <typename> struct state_setter;
84 ///////////////////////////////////////////////////////////////////////////////
86 BOOST_PHOENIX_DEFINE_EXPRESSION(
87 (boost)(spirit)(lex)(value_setter)
88 , (boost::phoenix::meta_grammar)
91 BOOST_PHOENIX_DEFINE_EXPRESSION(
92 (boost)(spirit)(lex)(state_setter)
93 , (boost::phoenix::meta_grammar)
96 namespace boost { namespace phoenix
101 struct is_nullary<custom_terminal<boost::spirit::lex::value_context> >
106 template <typename Dummy>
107 struct is_custom_terminal<boost::spirit::lex::value_context, Dummy>: mpl::true_ {};
109 template <typename Dummy>
110 struct custom_terminal<boost::spirit::lex::value_context, Dummy>
113 proto::make<boost::spirit::lex::value_getter()>
114 , proto::call<functional::env(proto::_state)>
119 template <typename Dummy>
120 struct is_nullary::when<spirit::lex::rule::value_setter, Dummy>
121 : proto::make<mpl::false_()>
124 template <typename Dummy>
125 struct default_actions::when<spirit::lex::rule::value_setter, Dummy>
129 spirit::lex::value_setter<proto::_child0>(
139 struct actor<spirit::lex::value_context>
140 : boost::phoenix::actor<proto::terminal<spirit::lex::value_context>::type>
142 typedef boost::phoenix::actor<
143 proto::terminal<spirit::lex::value_context>::type
146 actor(base_type const & base = base_type())
150 template <typename Expr>
151 typename spirit::lex::expression::value_setter<
152 typename phoenix::as_actor<Expr>::type>::type const
153 operator=(Expr const & expr) const
156 spirit::lex::expression::value_setter<
157 typename phoenix::as_actor<Expr>::type
158 >::make(phoenix::as_actor<Expr>::convert(expr));
165 struct is_nullary<custom_terminal<boost::spirit::lex::state_context> >
170 template <typename Dummy>
171 struct is_custom_terminal<boost::spirit::lex::state_context, Dummy>: mpl::true_ {};
173 template <typename Dummy>
174 struct custom_terminal<boost::spirit::lex::state_context, Dummy>
177 proto::make<boost::spirit::lex::state_getter()>
178 , proto::call<functional::env(proto::_state)>
183 template <typename Dummy>
184 struct is_nullary::when<spirit::lex::rule::state_setter, Dummy>
185 : proto::make<mpl::false_()>
188 template <typename Dummy>
189 struct default_actions::when<spirit::lex::rule::state_setter, Dummy>
193 spirit::lex::state_setter<proto::_child0>(
203 struct actor<spirit::lex::state_context>
204 : boost::phoenix::actor<proto::terminal<spirit::lex::state_context>::type>
206 typedef boost::phoenix::actor<
207 proto::terminal<spirit::lex::state_context>::type
210 actor(base_type const & base = base_type())
214 template <typename Expr>
215 typename spirit::lex::expression::state_setter<
216 typename phoenix::as_actor<Expr>::type>::type const
217 operator=(Expr const & expr) const
220 spirit::lex::expression::state_setter<
221 typename phoenix::as_actor<Expr>::type
222 >::make(phoenix::as_actor<Expr>::convert(expr));
229 struct is_nullary<custom_terminal<boost::spirit::lex::eoi_getter> >
234 template <typename Dummy>
235 struct is_custom_terminal<boost::spirit::lex::eoi_getter, Dummy>: mpl::true_ {};
237 template <typename Dummy>
238 struct custom_terminal<boost::spirit::lex::eoi_getter, Dummy>
241 proto::make<boost::spirit::lex::eoi_getter()>
242 , proto::call<functional::env(proto::_state)>