match_manip.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_SPIRIT_MATCH_MANIP_MAY_05_2007_1202PM)
  8. #define BOOST_SPIRIT_MATCH_MANIP_MAY_05_2007_1202PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/spirit/home/qi/parse.hpp>
  13. #include <boost/spirit/home/qi/parser.hpp>
  14. #include <boost/spirit/home/support/unused.hpp>
  15. #include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <iosfwd>
  18. ///////////////////////////////////////////////////////////////////////////////
  19. namespace boost { namespace spirit { namespace qi
  20. {
  21. ///////////////////////////////////////////////////////////////////////////
  22. template <typename Expr>
  23. inline typename detail::match<Expr>::type
  24. match(
  25. Expr const& expr)
  26. {
  27. return detail::match<Expr>::call(expr);
  28. }
  29. template <typename Expr, typename Attribute>
  30. inline detail::match_manip<
  31. Expr, mpl::false_, mpl::false_, unused_type, Attribute
  32. >
  33. match(
  34. Expr const& xpr
  35. , Attribute& p)
  36. {
  37. using qi::detail::match_manip;
  38. // Report invalid expression error as early as possible.
  39. // If you got an error_invalid_expression error message here,
  40. // then the expression (expr) is not a valid spirit qi expression.
  41. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  42. return match_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute>(
  43. xpr, unused, p);
  44. }
  45. ///////////////////////////////////////////////////////////////////////////
  46. template <typename Expr, typename Skipper>
  47. inline typename detail::phrase_match<Expr, Skipper>::type
  48. phrase_match(
  49. Expr const& expr
  50. , Skipper const& s
  51. , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
  52. {
  53. return detail::phrase_match<Expr, Skipper>::call(expr, s, post_skip);
  54. }
  55. template <typename Expr, typename Skipper, typename Attribute>
  56. inline detail::match_manip<
  57. Expr, mpl::false_, mpl::false_, Skipper, Attribute
  58. >
  59. phrase_match(
  60. Expr const& xpr
  61. , Skipper const& s
  62. , BOOST_SCOPED_ENUM(skip_flag) post_skip
  63. , Attribute& p)
  64. {
  65. using qi::detail::match_manip;
  66. // Report invalid expression error as early as possible.
  67. // If you got an error_invalid_expression error message here,
  68. // then either the expression (expr) or skipper is not a valid
  69. // spirit qi expression.
  70. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
  71. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
  72. return match_manip<Expr, mpl::false_, mpl::false_, Skipper, Attribute>(
  73. xpr, s, post_skip, p);
  74. }
  75. template <typename Expr, typename Skipper, typename Attribute>
  76. inline detail::match_manip<
  77. Expr, mpl::false_, mpl::false_, Skipper, Attribute
  78. >
  79. phrase_match(
  80. Expr const& xpr
  81. , Skipper const& s
  82. , Attribute& p)
  83. {
  84. using qi::detail::match_manip;
  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. return match_manip<Expr, mpl::false_, mpl::false_, Skipper, Attribute>(
  92. xpr, s, p);
  93. }
  94. ///////////////////////////////////////////////////////////////////////////
  95. template<typename Char, typename Traits, typename Derived>
  96. inline std::basic_istream<Char, Traits>&
  97. operator>>(std::basic_istream<Char, Traits>& is, parser<Derived> const& p)
  98. {
  99. typedef spirit::basic_istream_iterator<Char, Traits> input_iterator;
  100. input_iterator f(is);
  101. input_iterator l;
  102. if (!p.derived().parse(f, l, unused, unused, unused))
  103. {
  104. is.setstate(std::basic_istream<Char, Traits>::failbit);
  105. }
  106. return is;
  107. }
  108. }}}
  109. #endif