if_p_as_parser_tests.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*=============================================================================
  2. Copyright (c) 2003 Martin Wille
  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. #include <boost/spirit/include/classic_core.hpp>
  9. #include <boost/spirit/include/classic_if.hpp>
  10. extern bool fun();
  11. struct ftor
  12. {
  13. bool operator()() const;
  14. };
  15. int
  16. main()
  17. {
  18. //////////////////////////////////
  19. // compile time check wether as_parser<> works for if_p
  20. ::BOOST_SPIRIT_CLASSIC_NS::rule<> r;
  21. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p('-')['-'];
  22. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p("-")["-"];
  23. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p('-')['-'].else_p['-'];
  24. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p("-")["-"].else_p["-"];
  25. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(&fun)["foo"];
  26. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(ftor())["foo"];
  27. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(&fun)["foo"].else_p["bar"];
  28. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(ftor())["foo"].else_p["bar"];
  29. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(r)[r];
  30. r = ::BOOST_SPIRIT_CLASSIC_NS::if_p(r)[r].else_p[r];
  31. }