match_manip.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Hartmut Kaiser
  3. Copyright (c) 2001-2010 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_TEST_MATCH_MANIP_HPP)
  8. #define BOOST_SPIRIT_TEST_MATCH_MANIP_HPP
  9. #include <boost/config/warning_disable.hpp>
  10. #include <boost/spirit/include/support_argument.hpp>
  11. #include <boost/spirit/include/qi_action.hpp>
  12. #include <boost/spirit/include/qi_numeric.hpp>
  13. #include <boost/spirit/include/qi_operator.hpp>
  14. #include <boost/spirit/include/qi_char.hpp>
  15. #include <boost/spirit/include/qi_operator.hpp>
  16. #include <boost/spirit/include/qi_stream.hpp>
  17. #include <boost/spirit/include/qi_match.hpp>
  18. #include <boost/spirit/include/qi_match_auto.hpp>
  19. #include <boost/spirit/include/phoenix_core.hpp>
  20. #include <boost/spirit/include/phoenix_operator.hpp>
  21. #include <boost/spirit/include/phoenix_statement.hpp>
  22. #include <string>
  23. #include <sstream>
  24. #include <vector>
  25. #include <list>
  26. #include <boost/detail/lightweight_test.hpp>
  27. ///////////////////////////////////////////////////////////////////////////////
  28. template <typename Char, typename Expr>
  29. bool test(Char const *toparse, Expr const& expr)
  30. {
  31. namespace spirit = boost::spirit;
  32. BOOST_SPIRIT_ASSERT_MATCH(spirit::qi::domain, Expr);
  33. std::istringstream istrm(toparse);
  34. istrm.unsetf(std::ios::skipws);
  35. istrm >> spirit::qi::compile<spirit::qi::domain>(expr);
  36. return istrm.good() || istrm.eof();
  37. }
  38. template <typename Char, typename Expr, typename CopyExpr, typename CopyAttr
  39. , typename Skipper, typename Attribute>
  40. bool test(Char const *toparse,
  41. boost::spirit::qi::detail::match_manip<
  42. Expr, CopyExpr, CopyAttr, Skipper, Attribute> const& mm)
  43. {
  44. std::istringstream istrm(toparse);
  45. istrm.unsetf(std::ios::skipws);
  46. istrm >> mm;
  47. return istrm.good() || istrm.eof();
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////
  50. bool is_list_ok(std::list<char> const& l)
  51. {
  52. std::list<char>::const_iterator cit = l.begin();
  53. if (cit == l.end() || *cit != 'a')
  54. return false;
  55. if (++cit == l.end() || *cit != 'b')
  56. return false;
  57. return ++cit != l.end() && *cit == 'c';
  58. }
  59. #endif