seek.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*//////////////////////////////////////////////////////////////////////////////
  2. Copyright (c) 2011 Jamboree
  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. // [ Jamboree Oct 27, 2011 ] new example.
  7. #include <cstdlib>
  8. #include <iostream>
  9. #include <boost/spirit/include/qi.hpp>
  10. #include <boost/spirit/repository/include/qi_seek.hpp>
  11. int main()
  12. {
  13. //[reference_qi_seek_namespace
  14. namespace qi = boost::spirit::qi;
  15. namespace repo = boost::spirit::repository;
  16. //]
  17. typedef std::string::const_iterator iterator;
  18. //[reference_qi_seek_vars
  19. std::string str("/*C-style comment*/");
  20. iterator it = str.begin();
  21. iterator end = str.end();
  22. //]
  23. //[reference_qi_seek_parse
  24. if (qi::parse(it, end, "/*" >> repo::qi::seek["*/"]))
  25. {
  26. std::cout << "-------------------------------- \n";
  27. std::cout << "Parsing succeeded.\n";
  28. std::cout << "---------------------------------\n";
  29. }
  30. else
  31. {
  32. std::cout << "-------------------------------- \n";
  33. std::cout << "Unterminated /* comment.\n";
  34. std::cout << "-------------------------------- \n";
  35. }//]
  36. return EXIT_SUCCESS;
  37. }