1/*=============================================================================
2 Copyright (c) 2001-2011 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#if defined(_MSC_VER)
9# pragma warning(disable: 4180) // qualifier applied to function type
10 // has no meaning; ignored
11#endif
12
13// This tests the new behavior allowing attribute compatibility
14// to semantic actions
15
16#define BOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT
17
18#include <boost/spirit/include/qi_action.hpp>
19
20#include <boost/detail/workaround.hpp>
21#include <boost/spirit/include/qi.hpp>
22#include <boost/phoenix/bind.hpp>
23#include <string>
24#include "test.hpp"
25
26void f(std::string const& s)
27{
28 std::cout << "parsing got: " << s << std::endl;
29}
30
31std::string s;
32void b(char c)
33{
34 s += c;
35}
36
37int main()
38{
39 namespace qi = boost::spirit::qi;
40 namespace phoenix = boost::phoenix;
41 using spirit_test::test_attr;
42 using spirit_test::test;
43
44 {
45 qi::rule<char const*, std::string()> r;
46 r %= (+qi::char_)[phoenix::bind(f: &f, a: qi::_1)];
47
48 std::string attr;
49 BOOST_TEST(test_attr("abcdef", r, attr));
50 BOOST_TEST(attr == "abcdef");
51 }
52
53 { // chaining
54 using namespace boost::spirit::ascii;
55
56 s = "";
57 BOOST_TEST(test("a", char_[b][b]));
58 BOOST_TEST(s == "aa");
59 }
60
61 return boost::report_errors();
62}
63
64
65
66
67

source code of boost/libs/spirit/test/qi/actions2.cpp