argument_expression.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*=============================================================================
  2. Copyright (c) 2011 Thomas Heller
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Copyright (c) 2011 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #if !defined(BOOST_SPIRIT_ARGUMENT_MARCH_22_2011_0939PM)
  9. #define BOOST_SPIRIT_ARGUMENT_MARCH_22_2011_0939PM
  10. #include <boost/spirit/include/phoenix_core.hpp>
  11. namespace boost { namespace spirit
  12. {
  13. template <int N>
  14. struct argument;
  15. template <typename Dummy>
  16. struct attribute_context;
  17. namespace expression
  18. {
  19. #ifndef BOOST_SPIRIT_USE_PHOENIX_V3
  20. template <int N>
  21. struct argument
  22. {
  23. typedef phoenix::actor<spirit::argument<N> > type;
  24. static type make()
  25. {
  26. return spirit::argument<N>();
  27. }
  28. };
  29. template <typename Dummy>
  30. struct attribute_context
  31. {
  32. typedef phoenix::actor<spirit::attribute_context<Dummy> > type;
  33. static type make()
  34. {
  35. return spirit::attribute_context<Dummy>();
  36. }
  37. };
  38. #else
  39. template <int N>
  40. struct argument
  41. : phoenix::expression::terminal<spirit::argument<N> >
  42. {
  43. typedef typename phoenix::expression::terminal<
  44. spirit::argument<N>
  45. >::type type;
  46. static type make()
  47. {
  48. type const e = {{{}}};
  49. return e;
  50. }
  51. };
  52. template <typename Dummy>
  53. struct attribute_context
  54. : phoenix::expression::terminal<spirit::attribute_context<Dummy> >
  55. {
  56. typedef typename phoenix::expression::terminal<
  57. spirit::attribute_context<Dummy>
  58. >::type type;
  59. static type make()
  60. {
  61. type const e = {{{}}};
  62. return e;
  63. }
  64. };
  65. #endif
  66. }
  67. }}
  68. #ifdef BOOST_SPIRIT_USE_PHOENIX_V3
  69. namespace boost { namespace phoenix
  70. {
  71. namespace result_of
  72. {
  73. template <typename Dummy>
  74. struct is_nullary<custom_terminal<spirit::attribute_context<Dummy> > >
  75. : mpl::false_
  76. {};
  77. template <int N>
  78. struct is_nullary<custom_terminal<spirit::argument<N> > >
  79. : mpl::false_
  80. {};
  81. }
  82. template <typename Dummy>
  83. struct is_custom_terminal<spirit::attribute_context<Dummy> >
  84. : mpl::true_
  85. {};
  86. template <int N>
  87. struct is_custom_terminal<spirit::argument<N> >
  88. : mpl::true_
  89. {};
  90. template <typename Dummy>
  91. struct custom_terminal<spirit::attribute_context<Dummy> >
  92. : proto::call<
  93. v2_eval(
  94. proto::make<spirit::attribute_context<Dummy>()>
  95. , proto::call<
  96. functional::env(proto::_state)
  97. >
  98. )
  99. >
  100. {};
  101. template <int N>
  102. struct custom_terminal<spirit::argument<N> >
  103. : proto::call<
  104. v2_eval(
  105. proto::make<spirit::argument<N>()>
  106. , proto::call<
  107. functional::env(proto::_state)
  108. >
  109. )
  110. >
  111. {};
  112. }}
  113. #endif // BOOST_SPIRIT_USE_PHOENIX_V3
  114. #endif