annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/nonterminal/debug_handler.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_DEBUG_HANDLER_APR_21_2010_0148PM)
Chris@16 8 #define BOOST_SPIRIT_KARMA_DEBUG_HANDLER_APR_21_2010_0148PM
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/rule.hpp>
Chris@16 16 #include <boost/spirit/home/karma/nonterminal/debug_handler_state.hpp>
Chris@16 17 #include <boost/function.hpp>
Chris@16 18 #include <boost/fusion/include/at.hpp>
Chris@16 19 #include <boost/fusion/include/vector.hpp>
Chris@16 20 #include <boost/fusion/include/out.hpp>
Chris@16 21 #include <iostream>
Chris@16 22
Chris@16 23 namespace boost { namespace spirit { namespace karma
Chris@16 24 {
Chris@16 25 template <
Chris@16 26 typename OutputIterator, typename Context, typename Delimiter
Chris@16 27 , typename Properties, typename F>
Chris@16 28 struct debug_handler
Chris@16 29 {
Chris@16 30 typedef detail::output_iterator<OutputIterator, Properties>
Chris@16 31 output_iterator;
Chris@16 32 typedef detail::enable_buffering<output_iterator> buffer_type;
Chris@16 33
Chris@16 34 typedef function<bool(output_iterator&, Context&, Delimiter const&)>
Chris@16 35 function_type;
Chris@16 36
Chris@16 37 debug_handler(function_type subject, F f, std::string const& rule_name)
Chris@16 38 : subject(subject)
Chris@16 39 , f(f)
Chris@16 40 , rule_name(rule_name)
Chris@16 41 {}
Chris@16 42
Chris@16 43 bool operator()(output_iterator& sink, Context& context
Chris@16 44 , Delimiter const& delim) const
Chris@16 45 {
Chris@16 46 buffer_type buffer(sink);
Chris@16 47 bool r = false;
Chris@16 48
Chris@16 49 f (sink, context, pre_generate, rule_name, buffer);
Chris@16 50 {
Chris@16 51 detail::disable_counting<output_iterator> nocount(sink);
Chris@16 52 r = subject(sink, context, delim);
Chris@16 53 }
Chris@16 54
Chris@16 55 if (r)
Chris@16 56 {
Chris@16 57 f (sink, context, successful_generate, rule_name, buffer);
Chris@16 58 buffer.buffer_copy();
Chris@16 59 return true;
Chris@16 60 }
Chris@16 61 f (sink, context, failed_generate, rule_name, buffer);
Chris@16 62 return false;
Chris@16 63 }
Chris@16 64
Chris@16 65 function_type subject;
Chris@16 66 F f;
Chris@16 67 std::string rule_name;
Chris@16 68 };
Chris@16 69
Chris@16 70 template <typename OutputIterator
Chris@16 71 , typename T1, typename T2, typename T3, typename T4, typename F>
Chris@16 72 void debug(rule<OutputIterator, T1, T2, T3, T4>& r, F f)
Chris@16 73 {
Chris@16 74 typedef rule<OutputIterator, T1, T2, T3, T4> rule_type;
Chris@16 75
Chris@16 76 typedef
Chris@16 77 debug_handler<
Chris@16 78 OutputIterator
Chris@16 79 , typename rule_type::context_type
Chris@16 80 , typename rule_type::delimiter_type
Chris@16 81 , typename rule_type::properties
Chris@16 82 , F>
Chris@16 83 debug_handler;
Chris@16 84 r.f = debug_handler(r.f, f, r.name());
Chris@16 85 }
Chris@16 86
Chris@16 87 struct simple_trace;
Chris@16 88
Chris@16 89 namespace detail
Chris@16 90 {
Chris@16 91 // This class provides an extra level of indirection through a
Chris@16 92 // template to produce the simple_trace type. This way, the use
Chris@16 93 // of simple_trace below is hidden behind a dependent type, so
Chris@16 94 // that compilers eagerly type-checking template definitions
Chris@16 95 // won't complain that simple_trace is incomplete.
Chris@16 96 template<typename T>
Chris@16 97 struct get_simple_trace
Chris@16 98 {
Chris@16 99 typedef simple_trace type;
Chris@16 100 };
Chris@16 101 }
Chris@16 102
Chris@16 103 template <typename OutputIterator
Chris@16 104 , typename T1, typename T2, typename T3, typename T4>
Chris@16 105 void debug(rule<OutputIterator, T1, T2, T3, T4>& r)
Chris@16 106 {
Chris@16 107 typedef rule<OutputIterator, T1, T2, T3, T4> rule_type;
Chris@16 108
Chris@16 109 typedef
Chris@16 110 debug_handler<
Chris@16 111 OutputIterator
Chris@16 112 , typename rule_type::context_type
Chris@16 113 , typename rule_type::delimiter_type
Chris@16 114 , typename rule_type::properties
Chris@16 115 , simple_trace>
Chris@16 116 debug_handler;
Chris@16 117 typedef typename karma::detail::get_simple_trace<OutputIterator>::type
Chris@16 118 trace;
Chris@16 119 r.f = debug_handler(r.f, trace(), r.name());
Chris@16 120 }
Chris@16 121
Chris@16 122 }}}
Chris@16 123
Chris@16 124 ///////////////////////////////////////////////////////////////////////////////
Chris@16 125 // Utility macro for easy enabling of rule and grammar debugging
Chris@16 126 #if !defined(BOOST_SPIRIT_DEBUG_NODE)
Chris@16 127 #if defined(BOOST_SPIRIT_KARMA_DEBUG)
Chris@16 128 #define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r); debug(r)
Chris@16 129 #else
Chris@16 130 #define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r);
Chris@16 131 #endif
Chris@16 132 #endif
Chris@16 133
Chris@16 134 #endif