1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2001-2011 Joel de Guzman
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)
7 #if !defined(BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM)
8 #define BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM
14 #include <boost/spirit/home/support/unused.hpp>
15 #include <boost/spirit/home/karma/nonterminal/debug_handler_state.hpp>
16 #include <boost/fusion/include/out.hpp>
19 // The stream to use for debug output
20 #if !defined(BOOST_SPIRIT_DEBUG_OUT)
21 #define BOOST_SPIRIT_DEBUG_OUT std::cerr
24 // number of tokens to print while debugging
25 #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME)
26 #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20
29 // number of spaces to indent
30 #if !defined(BOOST_SPIRIT_DEBUG_INDENT)
31 #define BOOST_SPIRIT_DEBUG_INDENT 2
34 namespace boost { namespace spirit { namespace karma
38 int& get_indent() const
40 static int indent = 0;
44 void print_indent() const
47 n *= BOOST_SPIRIT_DEBUG_INDENT;
48 for (int i = 0; i != n; ++i)
49 BOOST_SPIRIT_DEBUG_OUT << ' ';
52 template <typename Buffer>
53 void print_some(char const* tag, Buffer const& buffer) const
56 BOOST_SPIRIT_DEBUG_OUT << '<' << tag << '>' << std::flush;
58 std::ostreambuf_iterator<char> out(BOOST_SPIRIT_DEBUG_OUT);
59 buffer.buffer_copy_to(out, BOOST_SPIRIT_DEBUG_PRINT_SOME);
61 BOOST_SPIRIT_DEBUG_OUT << "</" << tag << '>' << std::endl;
64 template <typename OutputIterator, typename Context, typename State
67 OutputIterator&, Context const& context
68 , State state, std::string const& rule_name
69 , Buffer const& buffer) const
76 BOOST_SPIRIT_DEBUG_OUT
77 << '<' << rule_name << '>' << std::endl;
80 BOOST_SPIRIT_DEBUG_OUT << "<try>" << std::endl;;
82 BOOST_SPIRIT_DEBUG_OUT << "<attributes>";
83 traits::print_attribute(
84 BOOST_SPIRIT_DEBUG_OUT,
87 BOOST_SPIRIT_DEBUG_OUT << "</attributes>" << std::endl;
88 if (!fusion::empty(context.locals))
91 BOOST_SPIRIT_DEBUG_OUT
92 << "<locals>" << context.locals << "</locals>"
97 BOOST_SPIRIT_DEBUG_OUT << "</try>" << std::endl;;
100 case successful_generate:
103 BOOST_SPIRIT_DEBUG_OUT << "<success>" << std::endl;
104 print_some("result", buffer);
105 if (!fusion::empty(context.locals))
108 BOOST_SPIRIT_DEBUG_OUT
109 << "<locals>" << context.locals << "</locals>"
114 BOOST_SPIRIT_DEBUG_OUT << "</success>" << std::endl;
117 BOOST_SPIRIT_DEBUG_OUT
118 << "</" << rule_name << '>' << std::endl;
121 case failed_generate:
123 BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl;
126 BOOST_SPIRIT_DEBUG_OUT
127 << "</" << rule_name << '>' << std::endl;