no_skip.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*=============================================================================
  2. Copyright (c) 2001-2015 Joel de Guzman
  3. Copyright (c) 2013 Agustin Berge
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/spirit/home/x3.hpp>
  9. #include <iostream>
  10. #include "test.hpp"
  11. int
  12. main()
  13. {
  14. using spirit_test::test;
  15. using spirit_test::test_attr;
  16. using boost::spirit::x3::ascii::space;
  17. using boost::spirit::x3::ascii::space_type;
  18. using boost::spirit::x3::ascii::char_;
  19. using boost::spirit::x3::lexeme;
  20. using boost::spirit::x3::no_skip;
  21. // without skipping no_skip is equivalent to lexeme
  22. {
  23. std::string str;
  24. BOOST_TEST((test_attr("' abc '", '\'' >> no_skip[+~char_('\'')] >> '\'', str)));
  25. BOOST_TEST(str == " abc ");
  26. }
  27. {
  28. std::string str;
  29. BOOST_TEST((test_attr("' abc '", '\'' >> lexeme[+~char_('\'')] >> '\'', str)));
  30. BOOST_TEST(str == " abc ");
  31. }
  32. // with skipping, no_skip allows to match a leading skipper
  33. {
  34. std::string str;
  35. BOOST_TEST((test_attr("' abc '", '\'' >> no_skip[+~char_('\'')] >> '\'', str, space)));
  36. BOOST_TEST(str == " abc ");
  37. }
  38. {
  39. std::string str;
  40. BOOST_TEST((test_attr("' abc '", '\'' >> lexeme[+~char_('\'')] >> '\'', str, space)));
  41. BOOST_TEST(str == "abc ");
  42. }
  43. return boost::report_errors();
  44. }