• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3 
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_PARSER_SEP_24_2007_0558PM)
8 #define BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM
9 
10 #include <boost/spirit/include/qi_parse.hpp>
11 #include <boost/spirit/include/qi_what.hpp>
12 
13 namespace spirit_test
14 {
15     template <typename Char, typename Parser, typename Lexer>
test_parser(Char const * in,Parser const & p,Lexer & lex,bool full_match=true)16     inline bool test_parser(Char const* in, Parser const& p, Lexer& lex,
17         bool full_match = true)
18     {
19         // we don't care about the result of the "what" function.
20         // we only care that all parsers have it:
21         boost::spirit::qi::what(p);
22 
23         std::string str (in);
24         std::string::iterator it_in = str.begin();
25         std::string::iterator end_in = str.end();
26 
27         typedef typename Lexer::iterator_type iterator_type;
28 
29         iterator_type iter = lex.begin(it_in, end_in);
30         iterator_type end = lex.end();
31 
32         return boost::spirit::qi::parse(iter, end, p)
33             && (!full_match || (iter == end));
34     }
35 
36     template <typename Char, typename Parser, typename Lexer, typename Skipper>
test_parser(Char const * in,Parser const & p,Lexer & lex,Skipper const & s,bool full_match=true)37     inline bool test_parser(Char const* in, Parser const& p, Lexer& lex,
38           Skipper const& s, bool full_match = true)
39     {
40         // we don't care about the result of the "what" function.
41         // we only care that all parsers have it:
42         boost::spirit::qi::what(p);
43 
44         std::string str (in);
45         std::string::iterator it_in = str.begin();
46         std::string::iterator end_in = str.end();
47 
48         typedef typename Lexer::iterator_type iterator_type;
49 
50         iterator_type iter = lex.begin(it_in, end_in);
51         iterator_type end = lex.end();
52 
53         return boost::spirit::qi::phrase_parse(iter, end, p, s)
54             && (!full_match || (iter == end));
55     }
56 
57 }
58 
59 #endif
60