lexeme.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*=============================================================================
  2. Copyright (c) 2001-2015 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/spirit/home/x3.hpp>
  8. #include <iostream>
  9. #include "test.hpp"
  10. int
  11. main()
  12. {
  13. using spirit_test::test;
  14. using boost::spirit::x3::ascii::space;
  15. using boost::spirit::x3::ascii::space_type;
  16. using boost::spirit::x3::ascii::digit;
  17. using boost::spirit::x3::lexeme;
  18. using boost::spirit::x3::rule;
  19. {
  20. BOOST_TEST((test(" 1 2 3 4 5", +digit, space)));
  21. BOOST_TEST((!test(" 1 2 3 4 5", lexeme[+digit], space)));
  22. BOOST_TEST((test(" 12345", lexeme[+digit], space)));
  23. BOOST_TEST((test(" 12345 ", lexeme[+digit], space, false)));
  24. // lexeme collapsing
  25. BOOST_TEST((!test(" 1 2 3 4 5", lexeme[lexeme[+digit]], space)));
  26. BOOST_TEST((test(" 12345", lexeme[lexeme[+digit]], space)));
  27. BOOST_TEST((test(" 12345 ", lexeme[lexeme[+digit]], space, false)));
  28. auto r = +digit;
  29. auto rr = lexeme[r];
  30. BOOST_TEST((!test(" 1 2 3 4 5", rr, space)));
  31. BOOST_TEST((test(" 12345", rr, space)));
  32. }
  33. return boost::report_errors();
  34. }