post_skips.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*=============================================================================
  2. Copyright (c) 2004 Joao Abecasis
  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_parser.hpp>
  9. #include <boost/spirit/include/classic_skipper.hpp>
  10. #include <boost/spirit/include/classic_primitives.hpp>
  11. #include <boost/spirit/include/classic_optional.hpp>
  12. #include <boost/spirit/include/classic_sequence.hpp>
  13. #include <boost/spirit/include/classic_ast.hpp>
  14. #include <boost/spirit/include/classic_parse_tree.hpp>
  15. #include <boost/detail/lightweight_test.hpp>
  16. using namespace BOOST_SPIRIT_CLASSIC_NS;
  17. char const * test1 = " 12345 ";
  18. char const * test2 = " 12345 x";
  19. void parse_tests()
  20. {
  21. parse_info<> info;
  22. // Warming up...
  23. info = parse(test1, str_p("12345"));
  24. BOOST_TEST(!info.hit);
  25. // No post-skips!
  26. info = parse(test1, str_p("12345"), blank_p);
  27. BOOST_TEST(info.hit);
  28. BOOST_TEST(!info.full);
  29. // Require a full match
  30. info = parse(test1, str_p("12345") >> end_p, blank_p);
  31. BOOST_TEST(info.full);
  32. info = parse(test2, str_p("12345") >> end_p, blank_p);
  33. BOOST_TEST(!info.hit);
  34. // Check for a full match but don't make it a requirement
  35. info = parse(test1, str_p("12345") >> !end_p, blank_p);
  36. BOOST_TEST(info.full);
  37. info = parse(test2, str_p("12345") >> !end_p, blank_p);
  38. BOOST_TEST(info.hit);
  39. BOOST_TEST(!info.full);
  40. }
  41. void ast_parse_tests()
  42. {
  43. tree_parse_info<> info;
  44. // Warming up...
  45. info = ast_parse(test1, str_p("12345"));
  46. BOOST_TEST(!info.match);
  47. // No post-skips!
  48. info = ast_parse(test1, str_p("12345"), blank_p);
  49. BOOST_TEST(info.match);
  50. BOOST_TEST(!info.full);
  51. // Require a full match
  52. info = ast_parse(test1, str_p("12345") >> end_p, blank_p);
  53. BOOST_TEST(info.full);
  54. info = ast_parse(test2, str_p("12345") >> end_p, blank_p);
  55. BOOST_TEST(!info.match);
  56. // Check for a full match but don't make it a requirement
  57. info = ast_parse(test1, str_p("12345") >> !end_p, blank_p);
  58. BOOST_TEST(info.full);
  59. info = ast_parse(test2, str_p("12345") >> !end_p, blank_p);
  60. BOOST_TEST(info.match);
  61. BOOST_TEST(!info.full);
  62. }
  63. void pt_parse_tests()
  64. {
  65. tree_parse_info<> info;
  66. // Warming up...
  67. info = pt_parse(test1, str_p("12345"));
  68. BOOST_TEST(!info.match);
  69. // No post-skips!
  70. info = pt_parse(test1, str_p("12345"), blank_p);
  71. BOOST_TEST(info.match);
  72. BOOST_TEST(!info.full);
  73. // Require a full match
  74. info = pt_parse(test1, str_p("12345") >> end_p, blank_p);
  75. BOOST_TEST(info.full);
  76. info = pt_parse(test2, str_p("12345") >> end_p, blank_p);
  77. BOOST_TEST(!info.match);
  78. // Check for a full match but don't make it a requirement
  79. info = pt_parse(test1, str_p("12345") >> !end_p, blank_p);
  80. BOOST_TEST(info.full);
  81. info = pt_parse(test2, str_p("12345") >> !end_p, blank_p);
  82. BOOST_TEST(info.match);
  83. BOOST_TEST(!info.full);
  84. }
  85. int main()
  86. {
  87. parse_tests();
  88. ast_parse_tests();
  89. pt_parse_tests();
  90. return boost::report_errors();
  91. }