summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/lex/test_parser.hpp
blob: 6a23cb34f2646179b429d594c14d897c05af988b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*=============================================================================
    Copyright (c) 2001-2011 Hartmut Kaiser

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM)
#define BOOST_SPIRIT_TEST_PARSER_SEP_24_2007_0558PM

#include <boost/spirit/include/qi_parse.hpp>
#include <boost/spirit/include/qi_what.hpp>

namespace spirit_test
{
    template <typename Char, typename Parser, typename Lexer>
    inline bool test_parser(Char const* in, Parser const& p, Lexer& lex, 
        bool full_match = true)
    {
        // we don't care about the result of the "what" function.
        // we only care that all parsers have it:
        boost::spirit::qi::what(p);

        std::string str (in);
        std::string::iterator it_in = str.begin();
        std::string::iterator end_in = str.end();

        typedef typename Lexer::iterator_type iterator_type;

        iterator_type iter = lex.begin(it_in, end_in);
        iterator_type end = lex.end();

        return boost::spirit::qi::parse(iter, end, p)
            && (!full_match || (iter == end));
    }

    template <typename Char, typename Parser, typename Lexer, typename Skipper>
    inline bool test_parser(Char const* in, Parser const& p, Lexer& lex,
          Skipper const& s, bool full_match = true)
    {
        // we don't care about the result of the "what" function.
        // we only care that all parsers have it:
        boost::spirit::qi::what(p);

        std::string str (in);
        std::string::iterator it_in = str.begin();
        std::string::iterator end_in = str.end();

        typedef typename Lexer::iterator_type iterator_type;

        iterator_type iter = lex.begin(it_in, end_in);
        iterator_type end = lex.end();

        return boost::spirit::qi::phrase_parse(iter, end, p, s)
            && (!full_match || (iter == end));
    }

}

#endif