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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*=============================================================================
Copyright (c) 2001-2010 Joel de Guzman
Copyright (c) 2016 Frank Hein, maxence business consulting gmbh
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)
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/qi_nonterminal.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <string>
#include <iostream>
#include "test.hpp"
int
main()
{
using namespace boost::spirit;
using namespace boost::spirit::ascii;
using spirit_test::test;
using spirit_test::print_info;
using boost::spirit::qi::expectation_failure;
{
try
{
BOOST_TEST((test("aa", expect[char_ >> char_])));
BOOST_TEST((test("aaa", expect[char_ >> char_ >> char_('a')])));
BOOST_TEST((test("xi", expect[char_('x') >> char_('i')])));
BOOST_TEST((test("xin", expect[char_('x') >> char_('i') >> char_('n')])));
BOOST_TEST((!test("xi", expect[char_('y')]))); // should throw!
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(boost::get<std::string>(x.what_.value) == "y");
BOOST_TEST(std::string(x.first, x.last) == "xi");
}
}
{
try
{
BOOST_TEST((!test("xi", expect[char_('x') >> char_('o')])));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(std::string(x.first, x.last) == "xi");
BOOST_TEST(x.what_.tag == "sequence");
}
}
{
try
{
BOOST_TEST((!test(" x i", expect[char_('x') >> char_('o')], space)));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(std::string(x.first, x.last) == " x i");
BOOST_TEST(x.what_.tag == "sequence");
}
}
{
try
{
BOOST_TEST((test(" a a", expect[char_ >> char_], space)));
BOOST_TEST((test(" x i", expect[char_('x') >> char_('i')], space)));
BOOST_TEST((!test(" x i", expect[char_('y')], space)));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(boost::get<std::string>(x.what_.value) == "y");
BOOST_TEST(std::string(x.first, x.last) == "x i");
}
}
{
try
{
BOOST_TEST((test("aA", expect[no_case[char_('a') >> 'a']])));
BOOST_TEST((test("BEGIN END", expect[no_case[lit("begin") >> "end"]], space)));
BOOST_TEST((!test("BEGIN END", expect[no_case[lit("begin") >> "nend"]], space)));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(x.what_.tag == "sequence");
BOOST_TEST(std::string(x.first, x.last) == "BEGIN END");
}
}
{
using boost::spirit::qi::rule;
using boost::spirit::eps;
rule<const wchar_t*, void(int)> r;
r = expect[eps(_r1)];
}
return boost::report_errors();
}
|