]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/regression_transform_assignment.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2011 Dean Michael Berries
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)
7 #include <boost/spirit/include/qi.hpp>
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/fusion/tuple.hpp>
15 boost::optional
<std::string
> first
;
19 namespace boost
{ namespace spirit
{ namespace traits
22 struct transform_attribute
<foo_parts
23 , fusion::tuple
<std::string
&, optional
<std::string
> &>
26 typedef fusion::tuple
<std::string
&, optional
<std::string
>&> type
;
28 static type
pre(foo_parts
& parts
)
30 return fusion::tie(parts
.second
, parts
.first
);
33 static void post(foo_parts
&, type
const &) {}
34 static void fail(foo_parts
&) {}
38 namespace qi
= boost::spirit::qi
;
40 template <typename Iterator
>
41 struct foo_grammar
: qi::grammar
<Iterator
, foo_parts()>
43 foo_grammar() : foo_grammar::base_type(start
, "foo")
46 +qi::alpha
>> -(+qi::digit
)
47 | qi::attr(std::string())
48 >> qi::attr(boost::optional
<std::string
>())
51 start
= foo_part
.alias();
54 typedef boost::fusion::tuple
<std::string
&, boost::optional
<std::string
>&>
57 qi::rule
<Iterator
, tuple_type()> foo_part
;
58 qi::rule
<Iterator
, foo_parts()> start
;
64 foo_grammar
<std::string::iterator
> grammar
;
65 std::string input
= "abc123";
67 BOOST_TEST(qi::parse(input
.begin(), input
.end(), grammar
, instance
) &&
68 instance
.first
&& instance
.first
.get() == "123" &&
69 instance
.second
== "abc");
71 return boost::report_errors();