]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/actions.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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 =============================================================================*/
9 # pragma warning(disable: 4180) // qualifier applied to function type
10 // has no meaning; ignored
13 #include <boost/spirit/include/qi_action.hpp>
15 #include <boost/detail/workaround.hpp>
16 #include <boost/spirit/include/qi_operator.hpp>
17 #include <boost/spirit/include/qi_numeric.hpp>
18 #include <boost/spirit/include/qi_char.hpp>
19 #include <boost/spirit/include/qi_parse.hpp>
21 #include <boost/core/lightweight_test.hpp>
22 #include <boost/lambda/lambda.hpp>
23 #include <boost/bind/bind.hpp>
27 // bogus https://developercommunity.visualstudio.com/t/buggy-warning-c4709/471956
28 # pragma warning(disable: 4709) // comma operator within array index expression
33 void fun1(int const& i
)
42 using boost::spirit::unused_type
;
46 void operator()(int const& i
, unused_type
, unused_type
) const
52 void fail (int, boost::spirit::unused_type
, bool& pass
)
59 setnext(char& next
) : next(next
) {}
61 void operator()(char c
, unused_type
, unused_type
) const
71 namespace qi
= boost::spirit::qi
;
72 using boost::spirit::int_
;
75 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
76 qi::parse(s1
, e1
, '{' >> int_
[&fun1
] >> '}');
80 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
81 qi::parse(s1
, e1
, '{' >> int_
[&fun2
] >> '}');
84 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1400)
86 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
87 qi::parse(s1
, e1
, '{' >> int_
[fun2
] >> '}');
90 x
+= 42; // compensate for missing test case
94 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
95 qi::parse(s1
, e1
, '{' >> int_
[fun_action()] >> '}');
99 using boost::placeholders::_1
;
100 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
101 qi::parse(s1
, e1
, '{' >> int_
[boost::bind(&fun1
, _1
)] >> '}');
105 namespace lambda
= boost::lambda
;
106 char const *s1
= "{42}", *e1
= s1
+ std::strlen(s1
);
107 qi::parse(s1
, e1
, '{' >> int_
[lambda::var(x
) += lambda::_1
] >> '}');
109 BOOST_TEST(x
== (42*6));
112 std::string
input("1234 6543");
114 BOOST_TEST(qi::phrase_parse(input
.begin(), input
.end(),
115 qi::int_
[fail
] | qi::digit
[setnext(next
)] , qi::space
));
116 BOOST_TEST(next
== '1');
119 return boost::report_errors();