match_manip_attr.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Copyright (c) 2001-2011 Joel de Guzman
  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_PP_IS_ITERATING)
  8. #if !defined(BOOST_SPIRIT_MATCH_MANIP_ATTR_MAY_05_2007_1202PM)
  9. #define BOOST_SPIRIT_MATCH_MANIP_ATTR_MAY_05_2007_1202PM
  10. #include <boost/spirit/home/qi/stream/match_manip.hpp>
  11. #include <boost/fusion/include/vector.hpp>
  12. #include <boost/preprocessor/iterate.hpp>
  13. #include <boost/preprocessor/repetition/enum.hpp>
  14. #include <boost/preprocessor/repetition/enum_params.hpp>
  15. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  16. #define BOOST_PP_FILENAME_1 \
  17. <boost/spirit/home/qi/stream/match_manip_attr.hpp>
  18. #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT)
  19. #include BOOST_PP_ITERATE()
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Preprocessor vertical repetition code
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. #else // defined(BOOST_PP_IS_ITERATING)
  27. #define N BOOST_PP_ITERATION()
  28. #define BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE(z, n, A) BOOST_PP_CAT(A, n) &
  29. ///////////////////////////////////////////////////////////////////////////////
  30. namespace boost { namespace spirit { namespace qi
  31. {
  32. ///////////////////////////////////////////////////////////////////////////
  33. template <typename Expr, BOOST_PP_ENUM_PARAMS(N, typename A)>
  34. inline detail::match_manip<Expr, mpl::false_, mpl::true_, unused_type
  35. , fusion::vector<
  36. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  37. > >
  38. match(
  39. Expr const& xpr
  40. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  41. {
  42. using qi::detail::match_manip;
  43. // Report invalid expression error as early as possible.
  44. // If you got an error_invalid_expression error message here,
  45. // then the expression (expr) is not a valid spirit qi expression.
  46. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  47. typedef fusion::vector<
  48. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  49. > vector_type;
  50. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  51. return match_manip<Expr, mpl::false_, mpl::true_, unused_type, vector_type>(
  52. xpr, unused, attr);
  53. }
  54. ///////////////////////////////////////////////////////////////////////////
  55. template <typename Expr, typename Skipper
  56. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  57. inline detail::match_manip<Expr, mpl::false_, mpl::true_, Skipper
  58. , fusion::vector<
  59. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  60. > >
  61. phrase_match(
  62. Expr const& xpr
  63. , Skipper const& s
  64. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  65. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  66. {
  67. using qi::detail::match_manip;
  68. // Report invalid expression error as early as possible.
  69. // If you got an error_invalid_expression error message here,
  70. // then either the expression (expr) or skipper is not a valid
  71. // spirit qi expression.
  72. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  73. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  74. typedef fusion::vector<
  75. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  76. > vector_type;
  77. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  78. return match_manip<Expr, mpl::false_, mpl::true_, Skipper, vector_type>(
  79. xpr, s, post_skip, attr);
  80. }
  81. template <typename Expr, typename Skipper
  82. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  83. inline detail::match_manip<Expr, mpl::false_, mpl::true_, Skipper
  84. , fusion::vector<
  85. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  86. > >
  87. phrase_match(
  88. Expr const& xpr
  89. , Skipper const& s
  90. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  91. {
  92. using qi::detail::match_manip;
  93. // Report invalid expression error as early as possible.
  94. // If you got an error_invalid_expression error message here,
  95. // then either the expression (expr) or skipper is not a valid
  96. // spirit qi expression.
  97. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  98. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  99. typedef fusion::vector<
  100. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  101. > vector_type;
  102. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  103. return match_manip<Expr, mpl::false_, mpl::true_, Skipper, vector_type>(
  104. xpr, s, attr);
  105. }
  106. }}}
  107. #undef BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE
  108. #undef N
  109. #endif