debug.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2001-2011 Joel de Guzman
  3. //
  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. #define BOOST_SPIRIT_KARMA_DEBUG
  7. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/spirit/include/karma_operator.hpp>
  9. #include <boost/spirit/include/karma_char.hpp>
  10. #include <boost/spirit/include/karma_string.hpp>
  11. #include <boost/spirit/include/karma_numeric.hpp>
  12. #include <boost/spirit/include/karma_auxiliary.hpp>
  13. #include <boost/spirit/include/karma_nonterminal.hpp>
  14. #include <boost/spirit/include/karma_action.hpp>
  15. #include <boost/spirit/include/phoenix_core.hpp>
  16. #include <boost/spirit/include/phoenix_operator.hpp>
  17. #include <boost/fusion/include/std_pair.hpp>
  18. #include <string>
  19. #include <cstring>
  20. #include <iostream>
  21. #include "test.hpp"
  22. int main()
  23. {
  24. using spirit_test::test;
  25. using spirit_test::test_delimited;
  26. using namespace boost::spirit::ascii;
  27. using namespace boost::spirit::karma::labels;
  28. using boost::spirit::karma::locals;
  29. using boost::spirit::karma::rule;
  30. using boost::spirit::karma::char_;
  31. using boost::spirit::karma::debug;
  32. using boost::spirit::karma::space;
  33. using boost::spirit::karma::eps;
  34. typedef spirit_test::output_iterator<char>::type outiter_type;
  35. { // basic tests
  36. rule<outiter_type, char()> a, b, c;
  37. rule<outiter_type, std::vector<char>()> start;
  38. std::vector<char> v;
  39. v.push_back('a');
  40. v.push_back('b');
  41. v.push_back('a');
  42. v.push_back('c');
  43. v.push_back('a');
  44. v.push_back('b');
  45. v.push_back('b');
  46. v.push_back('a');
  47. a = char_('a');
  48. b = char_('b');
  49. c = char_('c');
  50. BOOST_SPIRIT_DEBUG_NODE(a);
  51. BOOST_SPIRIT_DEBUG_NODE(b);
  52. BOOST_SPIRIT_DEBUG_NODE(c);
  53. start = *(a | b | c);
  54. BOOST_SPIRIT_DEBUG_NODE(start);
  55. BOOST_TEST(test("abacabba", start, v));
  56. // ignore the delimiter
  57. BOOST_TEST(test_delimited("abacabba ", start, v, space));
  58. std::vector<char> v1;
  59. v1.push_back('b');
  60. v1.push_back('c');
  61. start = (a | b) << c;
  62. BOOST_SPIRIT_DEBUG_NODE(start);
  63. BOOST_TEST(test("bc", start, v1));
  64. }
  65. { // tests with locals
  66. rule<outiter_type, char()> a, b, c;
  67. rule<outiter_type, std::vector<char>(), locals<int, double> > start;
  68. std::vector<char> v;
  69. v.push_back('a');
  70. v.push_back('b');
  71. v.push_back('a');
  72. v.push_back('c');
  73. v.push_back('a');
  74. v.push_back('b');
  75. v.push_back('b');
  76. v.push_back('a');
  77. a = char_('a');
  78. b = char_('b');
  79. c = char_('c');
  80. BOOST_SPIRIT_DEBUG_NODE(a);
  81. BOOST_SPIRIT_DEBUG_NODE(b);
  82. BOOST_SPIRIT_DEBUG_NODE(c);
  83. start %= eps[_a = 0, _b = 2.0] << *(a[++_a] | b | c);
  84. BOOST_SPIRIT_DEBUG_NODE(start);
  85. BOOST_TEST(test("abacabba", start, v));
  86. }
  87. return boost::report_errors();
  88. }