blob: f1ea338521988d8281805594ab482e5ed8b2e5cc (
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
60
61
62
63
64
65
66
67
68
69
70
71
|
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
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_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/qi_nonterminal.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
#include "test.hpp"
int
main()
{
using spirit_test::test;
using spirit_test::test_attr;
namespace qi = boost::spirit::qi;
using boost::spirit::qi::_1;
using boost::spirit::qi::_val;
using boost::spirit::qi::int_;
using boost::spirit::qi::rule;
using boost::spirit::ascii::char_;
using boost::phoenix::val;
using boost::phoenix::ref;
{
BOOST_TEST(test("123", val(int_)));
}
{
int result;
BOOST_TEST(test("123", qi::lazy(val(int_))[ref(result) = _1]));
BOOST_TEST((result == 123));
}
{
rule<char const*, char()> r;
r = char_[_val = _1] >> *qi::lazy(_val);
BOOST_TEST(test("aaaaaaaaaaaa", r));
BOOST_TEST(!test("abbbbbbbbbb", r));
BOOST_TEST(test("bbbbbbbbbbb", r));
}
{
rule<char const*, std::string()> r;
r =
'<' >> *(char_ - '>')[_val += _1] >> '>'
>> "</" >> qi::lazy(_val) >> '>'
;
BOOST_TEST(test("<tag></tag>", r));
BOOST_TEST(!test("<foo></bar>", r));
}
return boost::report_errors();
}
|