parse_attr.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2001-2011 Joel de Guzman
  3. // Copyright (c) 2009 Carl Barron
  4. //
  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. #if !defined(BOOST_PP_IS_ITERATING)
  8. #if !defined(BOOST_SPIRIT_PARSE_ATTR_APRIL_24_2009_1043AM)
  9. #define BOOST_SPIRIT_PARSE_ATTR_APRIL_24_2009_1043AM
  10. #include <boost/spirit/home/qi/parse.hpp>
  11. #include <boost/fusion/include/vector.hpp>
  12. #include <boost/preprocessor/cat.hpp>
  13. #include <boost/preprocessor/iterate.hpp>
  14. #include <boost/preprocessor/repetition/enum.hpp>
  15. #include <boost/preprocessor/repetition/enum_params.hpp>
  16. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  17. #define BOOST_PP_FILENAME_1 <boost/spirit/home/qi/parse_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. namespace boost { namespace spirit { namespace qi
  30. {
  31. ///////////////////////////////////////////////////////////////////////////
  32. template <typename Iterator, typename Expr
  33. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  34. inline bool
  35. parse(
  36. Iterator& first
  37. , Iterator last
  38. , Expr const& expr
  39. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  40. {
  41. // Make sure the iterator is at least a forward_iterator. If you got an
  42. // compilation error here, then you are using an input_iterator while
  43. // calling this function, you need to supply at least a
  44. // forward_iterator instead.
  45. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  46. // Report invalid expression error as early as possible.
  47. // If you got an error_invalid_expression error message here,
  48. // then the expression (expr) is not a valid spirit qi expression.
  49. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  50. typedef fusion::vector<
  51. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  52. > vector_type;
  53. vector_type lattr (BOOST_PP_ENUM_PARAMS(N, attr));
  54. return compile<qi::domain>(expr).parse(first, last, unused, unused, lattr);
  55. }
  56. template <typename Iterator, typename Expr
  57. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  58. inline bool
  59. parse(
  60. Iterator const& first_
  61. , Iterator last
  62. , Expr const& expr
  63. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  64. {
  65. Iterator first = first_;
  66. return qi::parse(first, last, expr, BOOST_PP_ENUM_PARAMS(N, attr));
  67. }
  68. ///////////////////////////////////////////////////////////////////////////
  69. template <typename Iterator, typename Expr, typename Skipper
  70. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  71. inline bool
  72. phrase_parse(
  73. Iterator& first
  74. , Iterator last
  75. , Expr const& expr
  76. , Skipper const& skipper
  77. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  78. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  79. {
  80. // Make sure the iterator is at least a forward_iterator. If you got an
  81. // compilation error here, then you are using an input_iterator while
  82. // calling this function, you need to supply at least a
  83. // forward_iterator instead.
  84. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  85. // Report invalid expression error as early as possible.
  86. // If you got an error_invalid_expression error message here,
  87. // then either the expression (expr) or skipper is not a valid
  88. // spirit qi expression.
  89. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  90. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  91. typedef
  92. typename result_of::compile<qi::domain, Skipper>::type
  93. skipper_type;
  94. skipper_type const skipper_ = compile<qi::domain>(skipper);
  95. typedef fusion::vector<
  96. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  97. > vector_type;
  98. vector_type lattr (BOOST_PP_ENUM_PARAMS(N, attr));
  99. if (!compile<qi::domain>(expr).parse(
  100. first, last, unused, skipper_, lattr))
  101. return false;
  102. if (post_skip == skip_flag::postskip)
  103. qi::skip_over(first, last, skipper_);
  104. return true;
  105. }
  106. template <typename Iterator, typename Expr, typename Skipper
  107. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  108. inline bool
  109. phrase_parse(
  110. Iterator const& first_
  111. , Iterator last
  112. , Expr const& expr
  113. , Skipper const& skipper
  114. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  115. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  116. {
  117. Iterator first = first_;
  118. return qi::phrase_parse(first, last, expr, skipper, post_skip
  119. , BOOST_PP_ENUM_PARAMS(N, attr));
  120. }
  121. ///////////////////////////////////////////////////////////////////////////
  122. template <typename Iterator, typename Expr, typename Skipper
  123. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  124. inline bool
  125. phrase_parse(
  126. Iterator& first
  127. , Iterator last
  128. , Expr const& expr
  129. , Skipper const& skipper
  130. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  131. {
  132. return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip
  133. , BOOST_PP_ENUM_PARAMS(N, attr));
  134. }
  135. template <typename Iterator, typename Expr, typename Skipper
  136. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  137. inline bool
  138. phrase_parse(
  139. Iterator const& first_
  140. , Iterator last
  141. , Expr const& expr
  142. , Skipper const& skipper
  143. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  144. {
  145. Iterator first = first_;
  146. return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip
  147. , BOOST_PP_ENUM_PARAMS(N, attr));
  148. }
  149. }}}
  150. #undef BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE
  151. #undef N
  152. #endif