/Src/Dependencies/Boost/boost/spirit/home/qi/parse.hpp

http://hadesmem.googlecode.com/ · C++ Header · 215 lines · 156 code · 24 blank · 35 comment · 3 complexity · 67c126f4465079bf25d71147727aeead MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  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_PARSE_APRIL_16_2006_0442PM)
  8. #define BOOST_SPIRIT_PARSE_APRIL_16_2006_0442PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/spirit/home/support/context.hpp>
  13. #include <boost/spirit/home/support/nonterminal/locals.hpp>
  14. #include <boost/spirit/home/qi/detail/parse.hpp>
  15. #include <boost/concept_check.hpp>
  16. namespace boost { namespace spirit { namespace qi
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. template <typename Iterator, typename Expr>
  20. inline bool
  21. parse(
  22. Iterator& first
  23. , Iterator last
  24. , Expr const& expr)
  25. {
  26. // Make sure the iterator is at least a forward_iterator. If you got a
  27. // compilation error here, then you are using an input_iterator while
  28. // calling this function, you need to supply at least a
  29. // forward_iterator instead.
  30. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  31. return detail::parse_impl<Expr>::call(first, last, expr);
  32. }
  33. template <typename Iterator, typename Expr>
  34. inline bool
  35. parse(
  36. Iterator const& first_
  37. , Iterator last
  38. , Expr const& expr)
  39. {
  40. Iterator first = first_;
  41. return qi::parse(first, last, expr);
  42. }
  43. ///////////////////////////////////////////////////////////////////////////
  44. namespace detail
  45. {
  46. template <typename T>
  47. struct make_context
  48. {
  49. typedef context<fusion::cons<T&>, locals<> > type;
  50. };
  51. template <>
  52. struct make_context<unused_type>
  53. {
  54. typedef unused_type type;
  55. };
  56. }
  57. template <typename Iterator, typename Expr, typename Attr>
  58. inline bool
  59. parse(
  60. Iterator& first
  61. , Iterator last
  62. , Expr const& expr
  63. , Attr& attr)
  64. {
  65. // Make sure the iterator is at least a forward_iterator. If you got a
  66. // compilation error here, then you are using an input_iterator while
  67. // calling this function, you need to supply at least a
  68. // forward_iterator instead.
  69. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  70. // Report invalid expression error as early as possible.
  71. // If you got an error_invalid_expression error message here,
  72. // then the expression (expr) is not a valid spirit qi expression.
  73. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  74. typename detail::make_context<Attr>::type context(attr);
  75. return compile<qi::domain>(expr).parse(first, last, context, unused, attr);
  76. }
  77. template <typename Iterator, typename Expr, typename Attr>
  78. inline bool
  79. parse(
  80. Iterator const& first_
  81. , Iterator last
  82. , Expr const& expr
  83. , Attr& attr)
  84. {
  85. Iterator first = first_;
  86. return qi::parse(first, last, expr, attr);
  87. }
  88. ///////////////////////////////////////////////////////////////////////////
  89. template <typename Iterator, typename Expr, typename Skipper>
  90. inline bool
  91. phrase_parse(
  92. Iterator& first
  93. , Iterator last
  94. , Expr const& expr
  95. , Skipper const& skipper
  96. , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
  97. {
  98. // Make sure the iterator is at least a forward_iterator. If you got a
  99. // compilation error here, then you are using an input_iterator while
  100. // calling this function, you need to supply at least a
  101. // forward_iterator instead.
  102. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  103. return detail::phrase_parse_impl<Expr>::call(
  104. first, last, expr, skipper, post_skip);
  105. }
  106. template <typename Iterator, typename Expr, typename Skipper>
  107. inline bool
  108. phrase_parse(
  109. Iterator const& first_
  110. , Iterator last
  111. , Expr const& expr
  112. , Skipper const& skipper
  113. , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
  114. {
  115. Iterator first = first_;
  116. return qi::phrase_parse(first, last, expr, skipper, post_skip);
  117. }
  118. ///////////////////////////////////////////////////////////////////////////
  119. template <typename Iterator, typename Expr, typename Skipper, typename Attr>
  120. inline bool
  121. phrase_parse(
  122. Iterator& first
  123. , Iterator last
  124. , Expr const& expr
  125. , Skipper const& skipper
  126. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  127. , Attr& attr)
  128. {
  129. // Make sure the iterator is at least a forward_iterator. If you got a
  130. // compilation error here, then you are using an input_iterator while
  131. // calling this function, you need to supply at least a
  132. // forward_iterator instead.
  133. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  134. // Report invalid expression error as early as possible.
  135. // If you got an error_invalid_expression error message here,
  136. // then either the expression (expr) or skipper is not a valid
  137. // spirit qi expression.
  138. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  139. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  140. typedef
  141. typename result_of::compile<qi::domain, Skipper>::type
  142. skipper_type;
  143. skipper_type const skipper_ = compile<qi::domain>(skipper);
  144. typename detail::make_context<Attr>::type context(attr);
  145. if (!compile<qi::domain>(expr).parse(
  146. first, last, context, skipper_, attr))
  147. return false;
  148. if (post_skip == skip_flag::postskip)
  149. qi::skip_over(first, last, skipper_);
  150. return true;
  151. }
  152. template <typename Iterator, typename Expr, typename Skipper, typename Attr>
  153. inline bool
  154. phrase_parse(
  155. Iterator const& first_
  156. , Iterator last
  157. , Expr const& expr
  158. , Skipper const& skipper
  159. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  160. , Attr& attr)
  161. {
  162. Iterator first = first_;
  163. return qi::phrase_parse(first, last, expr, skipper, post_skip, attr);
  164. }
  165. ///////////////////////////////////////////////////////////////////////////
  166. template <typename Iterator, typename Expr, typename Skipper, typename Attr>
  167. inline bool
  168. phrase_parse(
  169. Iterator& first
  170. , Iterator last
  171. , Expr const& expr
  172. , Skipper const& skipper
  173. , Attr& attr)
  174. {
  175. return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
  176. }
  177. template <typename Iterator, typename Expr, typename Skipper, typename Attr>
  178. inline bool
  179. phrase_parse(
  180. Iterator const& first_
  181. , Iterator last
  182. , Expr const& expr
  183. , Skipper const& skipper
  184. , Attr& attr)
  185. {
  186. Iterator first = first_;
  187. return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
  188. }
  189. }}}
  190. #endif