quick.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 Peter Dimov.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. //
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. #include <boost/wave.hpp>
  8. #include <boost/wave/cpplexer/cpp_lex_token.hpp>
  9. #include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
  10. #include <iostream>
  11. int main()
  12. {
  13. std::string input(
  14. "#if 0\n"
  15. "6.28\n"
  16. "#else\n"
  17. "3.14\n"
  18. "#endif\n"
  19. );
  20. try
  21. {
  22. typedef boost::wave::cpplexer::lex_token<> token_type;
  23. typedef boost::wave::cpplexer::lex_iterator<token_type> lex_iterator_type;
  24. typedef boost::wave::context<std::string::iterator, lex_iterator_type> context_type;
  25. context_type ctx( input.begin(), input.end(), "input.cpp" );
  26. for( context_type::iterator_type first = ctx.begin(), last = ctx.end(); first != last; ++first )
  27. {
  28. std::cout << first->get_value();
  29. }
  30. return 0;
  31. }
  32. catch( boost::wave::cpp_exception const & x )
  33. {
  34. std::cerr << x.file_name() << "(" << x.line_no() << "): " << x.description() << std::endl;
  35. return 1;
  36. }
  37. catch( std::exception const & x )
  38. {
  39. std::cerr << "Exception: " << x.what() << std::endl;
  40. return 2;
  41. }
  42. }