parse.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #if !defined(BOOST_SPIRIT_DETAIL_PARSE_DEC_02_2009_0411PM)
  7. #define BOOST_SPIRIT_DETAIL_PARSE_DEC_02_2009_0411PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/meta_compiler.hpp>
  12. #include <boost/spirit/home/qi/skip_flag.hpp>
  13. #include <boost/spirit/home/qi/skip_over.hpp>
  14. #include <boost/spirit/home/support/unused.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. namespace boost { namespace spirit { namespace qi { namespace detail
  18. {
  19. ///////////////////////////////////////////////////////////////////////////
  20. template <typename Expr, typename Enable = void>
  21. struct parse_impl
  22. {
  23. // Report invalid expression error as early as possible.
  24. // If you got an error_invalid_expression error message here,
  25. // then the expression (expr) is not a valid spirit qi expression.
  26. // Did you intend to use the auto_ facilities while forgetting to
  27. // #include <boost/spirit/include/qi_auto.hpp>?
  28. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  29. };
  30. template <typename Expr>
  31. struct parse_impl<Expr
  32. , typename enable_if<traits::matches<qi::domain, Expr> >::type>
  33. {
  34. template <typename Iterator>
  35. static bool call(
  36. Iterator& first
  37. , Iterator last
  38. , Expr const& expr)
  39. {
  40. return compile<qi::domain>(expr).parse(
  41. first, last, unused, unused, unused);
  42. }
  43. };
  44. ///////////////////////////////////////////////////////////////////////////
  45. template <typename Expr, typename Enable = void>
  46. struct phrase_parse_impl
  47. {
  48. // Report invalid expression error as early as possible.
  49. // If you got an error_invalid_expression error message here,
  50. // then the expression (expr) is not a valid spirit qi expression.
  51. // Did you intend to use the auto_ facilities while forgetting to
  52. // #include <boost/spirit/include/qi_auto.hpp>?
  53. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  54. };
  55. template <typename Expr>
  56. struct phrase_parse_impl<Expr
  57. , typename enable_if<traits::matches<qi::domain, Expr> >::type>
  58. {
  59. template <typename Iterator, typename Skipper>
  60. static bool call(
  61. Iterator& first
  62. , Iterator last
  63. , Expr const& expr
  64. , Skipper const& skipper
  65. , BOOST_SCOPED_ENUM(skip_flag) post_skip)
  66. {
  67. // Report invalid expression error as early as possible.
  68. // If you got an error_invalid_expression error message here,
  69. // then the skipper is not a valid spirit qi expression.
  70. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  71. typedef
  72. typename result_of::compile<qi::domain, Skipper>::type
  73. skipper_type;
  74. skipper_type const skipper_ = compile<qi::domain>(skipper);
  75. if (!compile<qi::domain>(expr).parse(
  76. first, last, unused, skipper_, unused))
  77. return false;
  78. if (post_skip == skip_flag::postskip)
  79. qi::skip_over(first, last, skipper_);
  80. return true;
  81. }
  82. };
  83. }}}}
  84. #endif