actions2.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #if defined(_MSC_VER)
  7. # pragma warning(disable: 4180) // qualifier applied to function type
  8. // has no meaning; ignored
  9. #endif
  10. // This tests the new behavior allowing attribute compatibility
  11. // to semantic actions
  12. #define BOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT
  13. #include <boost/detail/lightweight_test.hpp>
  14. #include <boost/detail/workaround.hpp>
  15. #include <boost/spirit/include/qi.hpp>
  16. #include <boost/spirit/include/phoenix_bind.hpp>
  17. #include <string>
  18. #include "test.hpp"
  19. void f(std::string const& s)
  20. {
  21. std::cout << "parsing got: " << s << std::endl;
  22. }
  23. std::string s;
  24. void b(char c)
  25. {
  26. s += c;
  27. }
  28. int main()
  29. {
  30. namespace qi = boost::spirit::qi;
  31. namespace phoenix = boost::phoenix;
  32. using spirit_test::test_attr;
  33. using spirit_test::test;
  34. {
  35. qi::rule<char const*, std::string()> r;
  36. r %= (+qi::char_)[phoenix::bind(&f, qi::_1)];
  37. std::string attr;
  38. BOOST_TEST(test_attr("abcdef", r, attr));
  39. BOOST_TEST(attr == "abcdef");
  40. }
  41. { // chaining
  42. using namespace boost::spirit::ascii;
  43. s = "";
  44. BOOST_TEST(test("a", char_[b][b]));
  45. BOOST_TEST(s == "aa");
  46. }
  47. return boost::report_errors();
  48. }