test_parser.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_TEST_PARSER_SEP_24_2007_0558PM)
  7. #define BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM
  8. #include <boost/spirit/include/qi_parse.hpp>
  9. #include <boost/spirit/include/qi_what.hpp>
  10. namespace spirit_test
  11. {
  12. template <typename Char, typename Parser, typename Lexer>
  13. inline bool test_parser(Char const* in, Parser const& p, Lexer& lex,
  14. bool full_match = true)
  15. {
  16. // we don't care about the result of the "what" function.
  17. // we only care that all parsers have it:
  18. boost::spirit::qi::what(p);
  19. std::string str (in);
  20. std::string::iterator it_in = str.begin();
  21. std::string::iterator end_in = str.end();
  22. typedef typename Lexer::iterator_type iterator_type;
  23. iterator_type iter = lex.begin(it_in, end_in);
  24. iterator_type end = lex.end();
  25. return boost::spirit::qi::parse(iter, end, p)
  26. && (!full_match || (iter == end));
  27. }
  28. template <typename Char, typename Parser, typename Lexer, typename Skipper>
  29. inline bool test_parser(Char const* in, Parser const& p, Lexer& lex,
  30. Skipper const& s, bool full_match = true)
  31. {
  32. // we don't care about the result of the "what" function.
  33. // we only care that all parsers have it:
  34. boost::spirit::qi::what(p);
  35. std::string str (in);
  36. std::string::iterator it_in = str.begin();
  37. std::string::iterator end_in = str.end();
  38. typedef typename Lexer::iterator_type iterator_type;
  39. iterator_type iter = lex.begin(it_in, end_in);
  40. iterator_type end = lex.end();
  41. return boost::spirit::qi::phrase_parse(iter, end, p, s)
  42. && (!full_match || (iter == end));
  43. }
  44. }
  45. #endif