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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*=============================================================================
Copyright (c) 2004 Joao Abecasis
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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)
=============================================================================*/
#include <boost/spirit/include/classic_parser.hpp>
#include <boost/spirit/include/classic_skipper.hpp>
#include <boost/spirit/include/classic_primitives.hpp>
#include <boost/spirit/include/classic_optional.hpp>
#include <boost/spirit/include/classic_sequence.hpp>
#include <boost/spirit/include/classic_ast.hpp>
#include <boost/spirit/include/classic_parse_tree.hpp>
#include <boost/detail/lightweight_test.hpp>
using namespace BOOST_SPIRIT_CLASSIC_NS;
char const * test1 = " 12345 ";
char const * test2 = " 12345 x";
void parse_tests()
{
parse_info<> info;
// Warming up...
info = parse(test1, str_p("12345"));
BOOST_TEST(!info.hit);
// No post-skips!
info = parse(test1, str_p("12345"), blank_p);
BOOST_TEST(info.hit);
BOOST_TEST(!info.full);
// Require a full match
info = parse(test1, str_p("12345") >> end_p, blank_p);
BOOST_TEST(info.full);
info = parse(test2, str_p("12345") >> end_p, blank_p);
BOOST_TEST(!info.hit);
// Check for a full match but don't make it a requirement
info = parse(test1, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.full);
info = parse(test2, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.hit);
BOOST_TEST(!info.full);
}
void ast_parse_tests()
{
tree_parse_info<> info;
// Warming up...
info = ast_parse(test1, str_p("12345"));
BOOST_TEST(!info.match);
// No post-skips!
info = ast_parse(test1, str_p("12345"), blank_p);
BOOST_TEST(info.match);
BOOST_TEST(!info.full);
// Require a full match
info = ast_parse(test1, str_p("12345") >> end_p, blank_p);
BOOST_TEST(info.full);
info = ast_parse(test2, str_p("12345") >> end_p, blank_p);
BOOST_TEST(!info.match);
// Check for a full match but don't make it a requirement
info = ast_parse(test1, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.full);
info = ast_parse(test2, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.match);
BOOST_TEST(!info.full);
}
void pt_parse_tests()
{
tree_parse_info<> info;
// Warming up...
info = pt_parse(test1, str_p("12345"));
BOOST_TEST(!info.match);
// No post-skips!
info = pt_parse(test1, str_p("12345"), blank_p);
BOOST_TEST(info.match);
BOOST_TEST(!info.full);
// Require a full match
info = pt_parse(test1, str_p("12345") >> end_p, blank_p);
BOOST_TEST(info.full);
info = pt_parse(test2, str_p("12345") >> end_p, blank_p);
BOOST_TEST(!info.match);
// Check for a full match but don't make it a requirement
info = pt_parse(test1, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.full);
info = pt_parse(test2, str_p("12345") >> !end_p, blank_p);
BOOST_TEST(info.match);
BOOST_TEST(!info.full);
}
int main()
{
parse_tests();
ast_parse_tests();
pt_parse_tests();
return boost::report_errors();
}
|