annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/nonterminal/simple_trace.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 2 // Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3 //
Chris@16 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 #if !defined(BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM)
Chris@16 8 #define BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/support/unused.hpp>
Chris@16 15 #include <boost/spirit/home/karma/nonterminal/debug_handler_state.hpp>
Chris@16 16 #include <boost/fusion/include/out.hpp>
Chris@16 17 #include <iostream>
Chris@16 18
Chris@16 19 // The stream to use for debug output
Chris@16 20 #if !defined(BOOST_SPIRIT_DEBUG_OUT)
Chris@16 21 #define BOOST_SPIRIT_DEBUG_OUT std::cerr
Chris@16 22 #endif
Chris@16 23
Chris@16 24 // number of tokens to print while debugging
Chris@16 25 #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME)
Chris@16 26 #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20
Chris@16 27 #endif
Chris@16 28
Chris@16 29 // number of spaces to indent
Chris@16 30 #if !defined(BOOST_SPIRIT_DEBUG_INDENT)
Chris@16 31 #define BOOST_SPIRIT_DEBUG_INDENT 2
Chris@16 32 #endif
Chris@16 33
Chris@16 34 namespace boost { namespace spirit { namespace karma
Chris@16 35 {
Chris@16 36 struct simple_trace
Chris@16 37 {
Chris@16 38 int& get_indent() const
Chris@16 39 {
Chris@16 40 static int indent = 0;
Chris@16 41 return indent;
Chris@16 42 }
Chris@16 43
Chris@16 44 void print_indent() const
Chris@16 45 {
Chris@16 46 int n = get_indent();
Chris@16 47 n *= BOOST_SPIRIT_DEBUG_INDENT;
Chris@16 48 for (int i = 0; i != n; ++i)
Chris@16 49 BOOST_SPIRIT_DEBUG_OUT << ' ';
Chris@16 50 }
Chris@16 51
Chris@16 52 template <typename Buffer>
Chris@16 53 void print_some(char const* tag, Buffer const& buffer) const
Chris@16 54 {
Chris@16 55 print_indent();
Chris@16 56 BOOST_SPIRIT_DEBUG_OUT << '<' << tag << '>' << std::flush;
Chris@16 57 {
Chris@16 58 std::ostreambuf_iterator<char> out(BOOST_SPIRIT_DEBUG_OUT);
Chris@16 59 buffer.buffer_copy_to(out, BOOST_SPIRIT_DEBUG_PRINT_SOME);
Chris@16 60 }
Chris@16 61 BOOST_SPIRIT_DEBUG_OUT << "</" << tag << '>' << std::endl;
Chris@16 62 }
Chris@16 63
Chris@16 64 template <typename OutputIterator, typename Context, typename State
Chris@16 65 , typename Buffer>
Chris@16 66 void operator()(
Chris@16 67 OutputIterator&, Context const& context
Chris@16 68 , State state, std::string const& rule_name
Chris@16 69 , Buffer const& buffer) const
Chris@16 70 {
Chris@16 71 switch (state)
Chris@16 72 {
Chris@16 73 case pre_generate:
Chris@16 74 print_indent();
Chris@16 75 ++get_indent();
Chris@16 76 BOOST_SPIRIT_DEBUG_OUT
Chris@16 77 << '<' << rule_name << '>' << std::endl;
Chris@16 78 print_indent();
Chris@16 79 ++get_indent();
Chris@16 80 BOOST_SPIRIT_DEBUG_OUT << "<try>" << std::endl;;
Chris@16 81 print_indent();
Chris@16 82 BOOST_SPIRIT_DEBUG_OUT << "<attributes>";
Chris@16 83 traits::print_attribute(
Chris@16 84 BOOST_SPIRIT_DEBUG_OUT,
Chris@16 85 context.attributes
Chris@16 86 );
Chris@16 87 BOOST_SPIRIT_DEBUG_OUT << "</attributes>" << std::endl;
Chris@16 88 if (!fusion::empty(context.locals))
Chris@16 89 {
Chris@16 90 print_indent();
Chris@16 91 BOOST_SPIRIT_DEBUG_OUT
Chris@16 92 << "<locals>" << context.locals << "</locals>"
Chris@16 93 << std::endl;
Chris@16 94 }
Chris@16 95 --get_indent();
Chris@16 96 print_indent();
Chris@16 97 BOOST_SPIRIT_DEBUG_OUT << "</try>" << std::endl;;
Chris@16 98 break;
Chris@16 99
Chris@16 100 case successful_generate:
Chris@16 101 print_indent();
Chris@16 102 ++get_indent();
Chris@16 103 BOOST_SPIRIT_DEBUG_OUT << "<success>" << std::endl;
Chris@16 104 print_some("result", buffer);
Chris@16 105 if (!fusion::empty(context.locals))
Chris@16 106 {
Chris@16 107 print_indent();
Chris@16 108 BOOST_SPIRIT_DEBUG_OUT
Chris@16 109 << "<locals>" << context.locals << "</locals>"
Chris@16 110 << std::endl;
Chris@16 111 }
Chris@16 112 --get_indent();
Chris@16 113 print_indent();
Chris@16 114 BOOST_SPIRIT_DEBUG_OUT << "</success>" << std::endl;
Chris@16 115 --get_indent();
Chris@16 116 print_indent();
Chris@16 117 BOOST_SPIRIT_DEBUG_OUT
Chris@16 118 << "</" << rule_name << '>' << std::endl;
Chris@16 119 break;
Chris@16 120
Chris@16 121 case failed_generate:
Chris@16 122 print_indent();
Chris@16 123 BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl;
Chris@16 124 --get_indent();
Chris@16 125 print_indent();
Chris@16 126 BOOST_SPIRIT_DEBUG_OUT
Chris@16 127 << "</" << rule_name << '>' << std::endl;
Chris@16 128 break;
Chris@16 129 }
Chris@16 130 }
Chris@16 131 };
Chris@16 132 }}}
Chris@16 133
Chris@16 134 #endif