match_manip.hpp 4.2 KB

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