Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Copyright (c) 2001-2011 Joel de Guzman Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if !defined(BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM) Chris@16: #define BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // The stream to use for debug output Chris@16: #if !defined(BOOST_SPIRIT_DEBUG_OUT) Chris@16: #define BOOST_SPIRIT_DEBUG_OUT std::cerr Chris@16: #endif Chris@16: Chris@16: // number of tokens to print while debugging Chris@16: #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME) Chris@16: #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20 Chris@16: #endif Chris@16: Chris@16: // number of spaces to indent Chris@16: #if !defined(BOOST_SPIRIT_DEBUG_INDENT) Chris@16: #define BOOST_SPIRIT_DEBUG_INDENT 2 Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace spirit { namespace karma Chris@16: { Chris@16: struct simple_trace Chris@16: { Chris@16: int& get_indent() const Chris@16: { Chris@16: static int indent = 0; Chris@16: return indent; Chris@16: } Chris@16: Chris@16: void print_indent() const Chris@16: { Chris@16: int n = get_indent(); Chris@16: n *= BOOST_SPIRIT_DEBUG_INDENT; Chris@16: for (int i = 0; i != n; ++i) Chris@16: BOOST_SPIRIT_DEBUG_OUT << ' '; Chris@16: } Chris@16: Chris@16: template Chris@16: void print_some(char const* tag, Buffer const& buffer) const Chris@16: { Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << '<' << tag << '>' << std::flush; Chris@16: { Chris@16: std::ostreambuf_iterator out(BOOST_SPIRIT_DEBUG_OUT); Chris@16: buffer.buffer_copy_to(out, BOOST_SPIRIT_DEBUG_PRINT_SOME); Chris@16: } Chris@16: BOOST_SPIRIT_DEBUG_OUT << "' << std::endl; Chris@16: } Chris@16: Chris@16: template Chris@16: void operator()( Chris@16: OutputIterator&, Context const& context Chris@16: , State state, std::string const& rule_name Chris@16: , Buffer const& buffer) const Chris@16: { Chris@16: switch (state) Chris@16: { Chris@16: case pre_generate: Chris@16: print_indent(); Chris@16: ++get_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT Chris@16: << '<' << rule_name << '>' << std::endl; Chris@16: print_indent(); Chris@16: ++get_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl;; Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << ""; Chris@16: traits::print_attribute( Chris@16: BOOST_SPIRIT_DEBUG_OUT, Chris@16: context.attributes Chris@16: ); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl; Chris@16: if (!fusion::empty(context.locals)) Chris@16: { Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT Chris@16: << "" << context.locals << "" Chris@16: << std::endl; Chris@16: } Chris@16: --get_indent(); Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl;; Chris@16: break; Chris@16: Chris@16: case successful_generate: Chris@16: print_indent(); Chris@16: ++get_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl; Chris@16: print_some("result", buffer); Chris@16: if (!fusion::empty(context.locals)) Chris@16: { Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT Chris@16: << "" << context.locals << "" Chris@16: << std::endl; Chris@16: } Chris@16: --get_indent(); Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl; Chris@16: --get_indent(); Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT Chris@16: << "' << std::endl; Chris@16: break; Chris@16: Chris@16: case failed_generate: Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT << "" << std::endl; Chris@16: --get_indent(); Chris@16: print_indent(); Chris@16: BOOST_SPIRIT_DEBUG_OUT Chris@16: << "' << std::endl; Chris@16: break; Chris@16: } Chris@16: } Chris@16: }; Chris@16: }}} Chris@16: Chris@16: #endif