typeof.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*=============================================================================
  2. Copyright (c) 2002-2003 Joel de Guzman
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. // *** See the section "typeof" in chapter "Techniques" of
  9. // *** the Spirit documentation for information regarding
  10. // *** this snippet.
  11. #include <iostream>
  12. #include <boost/spirit/include/classic_core.hpp>
  13. #include <boost/typeof/typeof.hpp>
  14. #include <boost/assert.hpp>
  15. using namespace BOOST_SPIRIT_CLASSIC_NS;
  16. #define RULE(name, definition) BOOST_TYPEOF(definition) name = definition
  17. int
  18. main()
  19. {
  20. RULE(
  21. skipper,
  22. ( space_p
  23. | "//" >> *(anychar_p - '\n') >> '\n'
  24. | "/*" >> *(anychar_p - "*/") >> "*/"
  25. )
  26. );
  27. bool success = parse(
  28. "/*this is a comment*/\n//this is a c++ comment\n\n",
  29. *skipper).full;
  30. BOOST_ASSERT(success);
  31. std::cout << "SUCCESS!!!\n";
  32. return 0;
  33. }