typeof.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=============================================================================
  2. Copyright (c) 2001-2010 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. #include <boost/config/warning_disable.hpp>
  7. #include <boost/spirit/include/qi.hpp>
  8. #include <boost/spirit/include/qi_copy.hpp>
  9. #include <boost/spirit/include/support_auto.hpp>
  10. #include <iostream>
  11. #include <string>
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // Main program
  14. ///////////////////////////////////////////////////////////////////////////////
  15. int
  16. main()
  17. {
  18. using boost::spirit::ascii::space;
  19. using boost::spirit::ascii::char_;
  20. using boost::spirit::qi::parse;
  21. typedef std::string::const_iterator iterator_type;
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // this works for non-c++11 compilers
  24. #ifdef BOOST_NO_CXX11_AUTO_DECLARATIONS
  25. BOOST_SPIRIT_AUTO(qi, comment, "/*" >> *(char_ - "*/") >> "*/");
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // but this is better for c++11 compilers with auto
  28. #else
  29. using boost::spirit::qi::copy;
  30. auto comment = copy("/*" >> *(char_ - "*/") >> "*/");
  31. #endif
  32. std::string str = "/*This is a comment*/";
  33. std::string::const_iterator iter = str.begin();
  34. std::string::const_iterator end = str.end();
  35. bool r = parse(iter, end, comment);
  36. if (r && iter == end)
  37. {
  38. std::cout << "-------------------------\n";
  39. std::cout << "Parsing succeeded\n";
  40. std::cout << "-------------------------\n";
  41. }
  42. else
  43. {
  44. std::string rest(iter, end);
  45. std::cout << "-------------------------\n";
  46. std::cout << "Parsing failed\n";
  47. std::cout << "stopped at: \": " << rest << "\"\n";
  48. std::cout << "-------------------------\n";
  49. }
  50. return 0;
  51. }