]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/rule3.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / rule3.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2012 Joel de Guzman
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
8 // this file deliberately contains non-ascii characters
9 // boostinspect:noascii
10
11 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/spirit/home/x3.hpp>
13 #include <boost/fusion/include/std_pair.hpp>
14
15 #include <string>
16 #include <cstring>
17 #include <iostream>
18 #include "test.hpp"
19
20 using boost::spirit::x3::_val;
21
22 struct f
23 {
24 template <typename Context>
25 void operator()(Context const& ctx) const
26 {
27 _val(ctx) += _attr(ctx);
28 }
29 };
30
31 int main()
32 {
33 using spirit_test::test_attr;
34 using spirit_test::test;
35
36 using namespace boost::spirit::x3::ascii;
37 using boost::spirit::x3::rule;
38 using boost::spirit::x3::int_;
39 using boost::spirit::x3::lit;
40
41
42 { // synth attribute value-init
43
44 std::string s;
45 typedef rule<class r, std::string> rule_type;
46
47 auto rdef = rule_type()
48 = alpha [f()]
49 ;
50
51 BOOST_TEST(test_attr("abcdef", +rdef, s));
52 BOOST_TEST(s == "abcdef");
53 }
54
55 { // synth attribute value-init
56
57 std::string s;
58 typedef rule<class r, std::string> rule_type;
59
60 auto rdef = rule_type() =
61 alpha /
62 [](auto& ctx)
63 {
64 _val(ctx) += _attr(ctx);
65 }
66 ;
67
68 BOOST_TEST(test_attr("abcdef", +rdef, s));
69 BOOST_TEST(s == "abcdef");
70 }
71
72 return boost::report_errors();
73 }