parse_auto.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_AUTO_DEC_02_2009_0426PM)
  7. #define BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/parse.hpp>
  12. #include <boost/spirit/home/qi/auto/create_parser.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. #include <boost/mpl/not.hpp>
  15. #include <boost/mpl/and.hpp>
  16. namespace boost { namespace spirit { namespace qi { namespace detail
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. template <typename Expr>
  20. struct parse_impl<Expr
  21. , typename enable_if<
  22. mpl::and_<
  23. traits::meta_create_exists<qi::domain, Expr>
  24. , mpl::not_<traits::matches<qi::domain, Expr> > >
  25. >::type>
  26. {
  27. template <typename Iterator>
  28. static bool call(Iterator& first, Iterator last, Expr& expr)
  29. {
  30. return qi::parse(first, last, create_parser<Expr>(), expr);
  31. }
  32. template <typename Iterator>
  33. static bool call(Iterator& first, Iterator last, Expr const& expr)
  34. {
  35. return qi::parse(first, last, create_parser<Expr>()
  36. , const_cast<Expr&>(expr));
  37. }
  38. };
  39. ///////////////////////////////////////////////////////////////////////////
  40. template <typename Expr>
  41. struct phrase_parse_impl<Expr
  42. , typename enable_if<
  43. mpl::and_<
  44. traits::meta_create_exists<qi::domain, Expr>
  45. , mpl::not_<traits::matches<qi::domain, Expr> > >
  46. >::type>
  47. {
  48. template <typename Iterator, typename Skipper>
  49. static bool call(Iterator& first, Iterator last, Expr& expr
  50. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  51. {
  52. return qi::phrase_parse(first, last, create_parser<Expr>()
  53. , skipper, post_skip, expr);
  54. }
  55. template <typename Iterator, typename Skipper>
  56. static bool call(Iterator& first, Iterator last, Expr const& expr
  57. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  58. {
  59. return qi::phrase_parse(first, last, create_parser<Expr>()
  60. , skipper, post_skip, const_cast<Expr&>(expr));
  61. }
  62. };
  63. }}}}
  64. namespace boost { namespace spirit { namespace qi
  65. {
  66. ///////////////////////////////////////////////////////////////////////////
  67. template <typename Iterator, typename Expr>
  68. inline bool
  69. parse(
  70. Iterator& first
  71. , Iterator last
  72. , Expr& expr)
  73. {
  74. // Make sure the iterator is at least a forward_iterator. If you got a
  75. // compilation error here, then you are using an input_iterator while
  76. // calling this function, you need to supply at least a
  77. // forward_iterator instead.
  78. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  79. return detail::parse_impl<Expr>::call(first, last, expr);
  80. }
  81. ///////////////////////////////////////////////////////////////////////////
  82. template <typename Iterator, typename Expr, typename Skipper>
  83. inline bool
  84. phrase_parse(
  85. Iterator& first
  86. , Iterator last
  87. , Expr& expr
  88. , Skipper const& skipper
  89. , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
  90. {
  91. // Make sure the iterator is at least a forward_iterator. If you got a
  92. // compilation error here, then you are using an input_iterator while
  93. // calling this function, you need to supply at least a
  94. // forward_iterator instead.
  95. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  96. return detail::phrase_parse_impl<Expr>::call(
  97. first, last, expr, skipper, post_skip);
  98. }
  99. }}}
  100. #endif