/Src/Dependencies/Boost/boost/spirit/home/lex/argument_phoenix.hpp

http://hadesmem.googlecode.com/ · C++ Header · 251 lines · 190 code · 37 blank · 24 comment · 0 complexity · 158e714c61cafa3d72bb28be6928f6fa MD5 · raw file

  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. #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM)
  7. #define BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/include/phoenix_core.hpp>
  12. namespace boost { namespace spirit { namespace lex
  13. {
  14. ///////////////////////////////////////////////////////////////////////////
  15. // The value_context is used as a noop Phoenix actor to create the
  16. // placeholder '_val' (see below). It is a noop actor because it is used
  17. // as a placeholder only, while it is being converted either to a
  18. // value_getter (if used as a rvalue) or to a value_setter (if used as a
  19. // lvalue). The conversion is achieved by specializing and overloading a
  20. // couple of the Phoenix templates from the Phoenix expression composition
  21. // engine (see the end of this file).
  22. struct value_context
  23. {
  24. typedef mpl::true_ no_nullary;
  25. typedef unused_type result_type;
  26. template <typename Env>
  27. struct result
  28. {
  29. typedef unused_type type;
  30. };
  31. template <typename Env>
  32. unused_type
  33. eval(Env const& env) const
  34. {
  35. return unused;
  36. }
  37. };
  38. // forward declarations
  39. struct value_getter;
  40. template <typename> struct value_setter;
  41. ///////////////////////////////////////////////////////////////////////////
  42. // The state_context is used as a noop Phoenix actor to create the
  43. // placeholder '_state' (see below). It is a noop actor because it is used
  44. // as a placeholder only, while it is being converted either to a
  45. // state_getter (if used as a rvalue) or to a state_setter (if used as a
  46. // lvalue). The conversion is achieved by specializing and overloading a
  47. // couple of the Phoenix templates from the Phoenix expression composition
  48. // engine (see the end of this file).
  49. struct state_context
  50. {
  51. typedef mpl::true_ no_nullary;
  52. typedef unused_type result_type;
  53. template <typename Env>
  54. struct result
  55. {
  56. typedef unused_type type;
  57. };
  58. template <typename Env>
  59. unused_type
  60. eval(Env const& env) const
  61. {
  62. return unused;
  63. }
  64. };
  65. // forward declarations
  66. struct state_getter;
  67. template <typename> struct state_setter;
  68. struct eoi_getter;
  69. }}}
  70. ///////////////////////////////////////////////////////////////////////////////
  71. #ifdef BOOST_SPIRIT_USE_PHOENIX_V3
  72. BOOST_PHOENIX_DEFINE_EXPRESSION(
  73. (boost)(spirit)(lex)(value_setter)
  74. , (boost::phoenix::meta_grammar)
  75. )
  76. BOOST_PHOENIX_DEFINE_EXPRESSION(
  77. (boost)(spirit)(lex)(state_setter)
  78. , (boost::phoenix::meta_grammar)
  79. )
  80. namespace boost { namespace phoenix
  81. {
  82. namespace result_of
  83. {
  84. template <>
  85. struct is_nullary<custom_terminal<boost::spirit::lex::value_context> >
  86. : mpl::false_
  87. {};
  88. }
  89. template <typename Dummy>
  90. struct is_custom_terminal<boost::spirit::lex::value_context, Dummy>: mpl::true_ {};
  91. template <typename Dummy>
  92. struct custom_terminal<boost::spirit::lex::value_context, Dummy>
  93. : proto::call<
  94. v2_eval(
  95. proto::make<boost::spirit::lex::value_getter()>
  96. , proto::call<functional::env(proto::_state)>
  97. )
  98. >
  99. {};
  100. template <typename Dummy>
  101. struct is_nullary::when<spirit::lex::rule::value_setter, Dummy>
  102. : proto::make<mpl::false_()>
  103. {};
  104. template <typename Dummy>
  105. struct default_actions::when<spirit::lex::rule::value_setter, Dummy>
  106. : proto::call<
  107. v2_eval(
  108. proto::make<
  109. spirit::lex::value_setter<proto::_child0>(
  110. proto::_child0
  111. )
  112. >
  113. , _env
  114. )
  115. >
  116. {};
  117. template <>
  118. struct actor<spirit::lex::value_context>
  119. : boost::phoenix::actor<proto::terminal<spirit::lex::value_context>::type>
  120. {
  121. typedef boost::phoenix::actor<
  122. proto::terminal<spirit::lex::value_context>::type
  123. > base_type;
  124. actor(base_type const & base = base_type())
  125. : base_type(base)
  126. {}
  127. template <typename Expr>
  128. typename spirit::lex::expression::value_setter<
  129. typename phoenix::as_actor<Expr>::type>::type const
  130. operator=(Expr const & expr) const
  131. {
  132. return
  133. spirit::lex::expression::value_setter<
  134. typename phoenix::as_actor<Expr>::type
  135. >::make(phoenix::as_actor<Expr>::convert(expr));
  136. }
  137. };
  138. namespace result_of
  139. {
  140. template <>
  141. struct is_nullary<custom_terminal<boost::spirit::lex::state_context> >
  142. : mpl::false_
  143. {};
  144. }
  145. template <typename Dummy>
  146. struct is_custom_terminal<boost::spirit::lex::state_context, Dummy>: mpl::true_ {};
  147. template <typename Dummy>
  148. struct custom_terminal<boost::spirit::lex::state_context, Dummy>
  149. : proto::call<
  150. v2_eval(
  151. proto::make<boost::spirit::lex::state_getter()>
  152. , proto::call<functional::env(proto::_state)>
  153. )
  154. >
  155. {};
  156. template <typename Dummy>
  157. struct is_nullary::when<spirit::lex::rule::state_setter, Dummy>
  158. : proto::make<mpl::false_()>
  159. {};
  160. template <typename Dummy>
  161. struct default_actions::when<spirit::lex::rule::state_setter, Dummy>
  162. : proto::call<
  163. v2_eval(
  164. proto::make<
  165. spirit::lex::state_setter<proto::_child0>(
  166. proto::_child0
  167. )
  168. >
  169. , _env
  170. )
  171. >
  172. {};
  173. template <>
  174. struct actor<spirit::lex::state_context>
  175. : boost::phoenix::actor<proto::terminal<spirit::lex::state_context>::type>
  176. {
  177. typedef boost::phoenix::actor<
  178. proto::terminal<spirit::lex::state_context>::type
  179. > base_type;
  180. actor(base_type const & base = base_type())
  181. : base_type(base)
  182. {}
  183. template <typename Expr>
  184. typename spirit::lex::expression::state_setter<
  185. typename phoenix::as_actor<Expr>::type>::type const
  186. operator=(Expr const & expr) const
  187. {
  188. return
  189. spirit::lex::expression::state_setter<
  190. typename phoenix::as_actor<Expr>::type
  191. >::make(phoenix::as_actor<Expr>::convert(expr));
  192. }
  193. };
  194. namespace result_of
  195. {
  196. template <>
  197. struct is_nullary<custom_terminal<boost::spirit::lex::eoi_getter> >
  198. : mpl::false_
  199. {};
  200. }
  201. template <typename Dummy>
  202. struct is_custom_terminal<boost::spirit::lex::eoi_getter, Dummy>: mpl::true_ {};
  203. template <typename Dummy>
  204. struct custom_terminal<boost::spirit::lex::eoi_getter, Dummy>
  205. : proto::call<
  206. v2_eval(
  207. proto::make<boost::spirit::lex::eoi_getter()>
  208. , proto::call<functional::env(proto::_state)>
  209. )
  210. >
  211. {};
  212. }}
  213. #endif // BOOST_SPIRIT_USE_PHOENIX_V3
  214. #endif