• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/detail/lightweight_test.hpp>
19 #include <boost/detail/workaround.hpp>
20 #include <boost/spirit/include/qi.hpp>
21 #include <boost/spirit/include/phoenix_bind.hpp>
22 #include <string>
23 #include "test.hpp"
24 
f(std::string const & s)25 void f(std::string const& s)
26 {
27     std::cout << "parsing got: " << s << std::endl;
28 }
29 
30 std::string s;
b(char c)31 void b(char c)
32 {
33     s += c;
34 }
35 
main()36 int main()
37 {
38     namespace qi = boost::spirit::qi;
39     namespace phoenix = boost::phoenix;
40     using spirit_test::test_attr;
41     using spirit_test::test;
42 
43     {
44         qi::rule<char const*, std::string()> r;
45         r %= (+qi::char_)[phoenix::bind(&f, qi::_1)];
46 
47         std::string attr;
48         BOOST_TEST(test_attr("abcdef", r, attr));
49         BOOST_TEST(attr == "abcdef");
50     }
51 
52     { // chaining
53         using namespace boost::spirit::ascii;
54 
55         s = "";
56         BOOST_TEST(test("a", char_[b][b]));
57         BOOST_TEST(s == "aa");
58     }
59 
60     return boost::report_errors();
61 }
62 
63 
64 
65 
66