comparison DEPENDENCIES/generic/include/boost/spirit/home/lex/argument_phoenix.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2011 Thomas Heller
3 //
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)
6
7 #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM)
8 #define BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM
9
10 #if defined(_MSC_VER)
11 #pragma once
12 #endif
13
14 #include <boost/spirit/include/phoenix_core.hpp>
15
16 namespace boost { namespace spirit { namespace lex
17 {
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).
26 struct value_context
27 {
28 typedef mpl::true_ no_nullary;
29
30 typedef unused_type result_type;
31
32 template <typename Env>
33 struct result
34 {
35 typedef unused_type type;
36 };
37
38 template <typename Env>
39 unused_type
40 eval(Env const& env) const
41 {
42 return unused;
43 }
44 };
45
46 // forward declarations
47 struct value_getter;
48 template <typename> struct value_setter;
49
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).
58 struct state_context
59 {
60 typedef mpl::true_ no_nullary;
61
62 typedef unused_type result_type;
63
64 template <typename Env>
65 struct result
66 {
67 typedef unused_type type;
68 };
69
70 template <typename Env>
71 unused_type
72 eval(Env const& env) const
73 {
74 return unused;
75 }
76 };
77
78 // forward declarations
79 struct state_getter;
80 template <typename> struct state_setter;
81 struct eoi_getter;
82 }}}
83
84 ///////////////////////////////////////////////////////////////////////////////
85 #ifdef BOOST_SPIRIT_USE_PHOENIX_V3
86
87 BOOST_PHOENIX_DEFINE_EXPRESSION(
88 (boost)(spirit)(lex)(value_setter)
89 , (boost::phoenix::meta_grammar)
90 )
91
92 BOOST_PHOENIX_DEFINE_EXPRESSION(
93 (boost)(spirit)(lex)(state_setter)
94 , (boost::phoenix::meta_grammar)
95 )
96
97 namespace boost { namespace phoenix
98 {
99 namespace result_of
100 {
101 template <>
102 struct is_nullary<custom_terminal<boost::spirit::lex::value_context> >
103 : mpl::false_
104 {};
105 }
106
107 template <typename Dummy>
108 struct is_custom_terminal<boost::spirit::lex::value_context, Dummy>: mpl::true_ {};
109
110 template <typename Dummy>
111 struct custom_terminal<boost::spirit::lex::value_context, Dummy>
112 : proto::call<
113 v2_eval(
114 proto::make<boost::spirit::lex::value_getter()>
115 , proto::call<functional::env(proto::_state)>
116 )
117 >
118 {};
119
120 template <typename Dummy>
121 struct is_nullary::when<spirit::lex::rule::value_setter, Dummy>
122 : proto::make<mpl::false_()>
123 {};
124
125 template <typename Dummy>
126 struct default_actions::when<spirit::lex::rule::value_setter, Dummy>
127 : proto::call<
128 v2_eval(
129 proto::make<
130 spirit::lex::value_setter<proto::_child0>(
131 proto::_child0
132 )
133 >
134 , _env
135 )
136 >
137 {};
138
139 template <>
140 struct actor<spirit::lex::value_context>
141 : boost::phoenix::actor<proto::terminal<spirit::lex::value_context>::type>
142 {
143 typedef boost::phoenix::actor<
144 proto::terminal<spirit::lex::value_context>::type
145 > base_type;
146
147 actor(base_type const & base = base_type())
148 : base_type(base)
149 {}
150
151 template <typename Expr>
152 typename spirit::lex::expression::value_setter<
153 typename phoenix::as_actor<Expr>::type>::type const
154 operator=(Expr const & expr) const
155 {
156 return
157 spirit::lex::expression::value_setter<
158 typename phoenix::as_actor<Expr>::type
159 >::make(phoenix::as_actor<Expr>::convert(expr));
160 }
161 };
162
163 namespace result_of
164 {
165 template <>
166 struct is_nullary<custom_terminal<boost::spirit::lex::state_context> >
167 : mpl::false_
168 {};
169 }
170
171 template <typename Dummy>
172 struct is_custom_terminal<boost::spirit::lex::state_context, Dummy>: mpl::true_ {};
173
174 template <typename Dummy>
175 struct custom_terminal<boost::spirit::lex::state_context, Dummy>
176 : proto::call<
177 v2_eval(
178 proto::make<boost::spirit::lex::state_getter()>
179 , proto::call<functional::env(proto::_state)>
180 )
181 >
182 {};
183
184 template <typename Dummy>
185 struct is_nullary::when<spirit::lex::rule::state_setter, Dummy>
186 : proto::make<mpl::false_()>
187 {};
188
189 template <typename Dummy>
190 struct default_actions::when<spirit::lex::rule::state_setter, Dummy>
191 : proto::call<
192 v2_eval(
193 proto::make<
194 spirit::lex::state_setter<proto::_child0>(
195 proto::_child0
196 )
197 >
198 , _env
199 )
200 >
201 {};
202
203 template <>
204 struct actor<spirit::lex::state_context>
205 : boost::phoenix::actor<proto::terminal<spirit::lex::state_context>::type>
206 {
207 typedef boost::phoenix::actor<
208 proto::terminal<spirit::lex::state_context>::type
209 > base_type;
210
211 actor(base_type const & base = base_type())
212 : base_type(base)
213 {}
214
215 template <typename Expr>
216 typename spirit::lex::expression::state_setter<
217 typename phoenix::as_actor<Expr>::type>::type const
218 operator=(Expr const & expr) const
219 {
220 return
221 spirit::lex::expression::state_setter<
222 typename phoenix::as_actor<Expr>::type
223 >::make(phoenix::as_actor<Expr>::convert(expr));
224 }
225 };
226
227 namespace result_of
228 {
229 template <>
230 struct is_nullary<custom_terminal<boost::spirit::lex::eoi_getter> >
231 : mpl::false_
232 {};
233 }
234
235 template <typename Dummy>
236 struct is_custom_terminal<boost::spirit::lex::eoi_getter, Dummy>: mpl::true_ {};
237
238 template <typename Dummy>
239 struct custom_terminal<boost::spirit::lex::eoi_getter, Dummy>
240 : proto::call<
241 v2_eval(
242 proto::make<boost::spirit::lex::eoi_getter()>
243 , proto::call<functional::env(proto::_state)>
244 )
245 >
246 {};
247 }}
248
249 #endif // BOOST_SPIRIT_USE_PHOENIX_V3
250
251 #endif