no_actions.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*=============================================================================
  2. Copyright (c) 2003 Vaclav Vesely
  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. //
  9. // This example demonstrates no_actions_d directive.
  10. //
  11. // The no_actions_d directive ensures, that semantic actions of the inner
  12. // parser would NOT be invoked. See the no_actions_scanner in the Scanner
  13. // and Parsing chapter in the User's Guide.
  14. //
  15. //-----------------------------------------------------------------------------
  16. #include <boost/assert.hpp>
  17. #include <iostream>
  18. #include <boost/cstdlib.hpp>
  19. #include <boost/spirit/include/classic_core.hpp>
  20. using namespace std;
  21. using namespace boost;
  22. using namespace BOOST_SPIRIT_CLASSIC_NS;
  23. //-----------------------------------------------------------------------------
  24. int main()
  25. {
  26. // To use the rule in the no_action_d directive we must declare it with
  27. // the no_actions_scanner scanner
  28. rule<no_actions_scanner<>::type> r;
  29. int i(0);
  30. // r is the rule with the semantic action
  31. r = int_p[assign_a(i)];
  32. parse_info<> info = parse(
  33. "1",
  34. no_actions_d
  35. [
  36. r
  37. ]
  38. );
  39. BOOST_ASSERT(info.full);
  40. // Check, that the action hasn't been invoked
  41. BOOST_ASSERT(i == 0);
  42. return exit_success;
  43. }
  44. //-----------------------------------------------------------------------------