Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:45

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003     Copyright (c) 2001-2011 Hartmut Kaiser
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 #if !defined(BOOST_SPIRIT_SIMPLE_TRACE_DECEMBER_06_2008_1102AM)
0009 #define BOOST_SPIRIT_SIMPLE_TRACE_DECEMBER_06_2008_1102AM
0010 
0011 #if defined(_MSC_VER)
0012 #pragma once
0013 #endif
0014 
0015 #include <boost/spirit/home/support/unused.hpp>
0016 #include <boost/spirit/home/qi/nonterminal/debug_handler_state.hpp>
0017 #include <boost/fusion/include/out.hpp>
0018 #include <iostream>
0019 #include <boost/mpl/if.hpp>
0020 #include <boost/mpl/and.hpp>
0021 #include <boost/type_traits/is_convertible.hpp>
0022 #include <boost/spirit/home/support/attributes.hpp>
0023 
0024 //  The stream to use for debug output
0025 #if !defined(BOOST_SPIRIT_DEBUG_OUT)
0026 #define BOOST_SPIRIT_DEBUG_OUT std::cerr
0027 #endif
0028 
0029 //  number of tokens to print while debugging
0030 #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME)
0031 #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20
0032 #endif
0033 
0034 //  number of spaces to indent
0035 #if !defined(BOOST_SPIRIT_DEBUG_INDENT)
0036 #define BOOST_SPIRIT_DEBUG_INDENT 2
0037 #endif
0038 
0039 namespace boost { namespace spirit { namespace qi
0040 {
0041     namespace detail
0042     {
0043         template<typename Char>
0044         inline void token_printer(std::ostream& o, Char c)
0045         {
0046             // allow to customize the token printer routine
0047             spirit::traits::print_token(o, c);
0048         }
0049     }
0050 
0051     struct simple_trace
0052     {
0053         int& get_indent() const
0054         {
0055             static int indent = 0;
0056             return indent;
0057         }
0058 
0059         void print_indent(int n) const
0060         {
0061             n *= BOOST_SPIRIT_DEBUG_INDENT;
0062             for (int i = 0; i != n; ++i)
0063                 BOOST_SPIRIT_DEBUG_OUT << ' ';
0064         }
0065 
0066         template <typename Iterator>
0067         void print_some(
0068             char const* tag
0069           , int /*indent*/
0070           , Iterator first, Iterator const& last) const
0071         {
0072             print_indent(get_indent());
0073             BOOST_SPIRIT_DEBUG_OUT << '<' << tag << '>';
0074             int const n = BOOST_SPIRIT_DEBUG_PRINT_SOME;
0075             for (int i = 0; first != last && i != n && *first; ++i, ++first)
0076                 detail::token_printer(BOOST_SPIRIT_DEBUG_OUT, *first);
0077             BOOST_SPIRIT_DEBUG_OUT << "</" << tag << '>' << std::endl;
0078 
0079             // $$$ FIXME convert invalid xml characters (e.g. '<') to valid
0080             // character entities. $$$
0081         }
0082 
0083         template <typename Iterator, typename Context, typename State>
0084         void operator()(
0085             Iterator const& first
0086           , Iterator const& last
0087           , Context const& context
0088           , State state
0089           , std::string const& rule_name) const
0090         {
0091             switch (state)
0092             {
0093                 case pre_parse:
0094                     print_indent(get_indent()++);
0095                     BOOST_SPIRIT_DEBUG_OUT
0096                         << '<' << rule_name << '>'
0097                         << std::endl;
0098                     print_some("try", get_indent(), first, last);
0099                     break;
0100                 case successful_parse:
0101                     print_some("success", get_indent(), first, last);
0102                     print_indent(get_indent());
0103                     BOOST_SPIRIT_DEBUG_OUT
0104                         << "<attributes>";
0105                     traits::print_attribute(
0106                         BOOST_SPIRIT_DEBUG_OUT,
0107                         context.attributes
0108                     );
0109                     BOOST_SPIRIT_DEBUG_OUT
0110                         << "</attributes>";
0111                     if (!fusion::empty(context.locals))
0112                         BOOST_SPIRIT_DEBUG_OUT
0113                             << "<locals>"
0114                             << context.locals
0115                             << "</locals>";
0116                     BOOST_SPIRIT_DEBUG_OUT << std::endl;
0117                     print_indent(--get_indent());
0118                     BOOST_SPIRIT_DEBUG_OUT
0119                         << "</" << rule_name << '>'
0120                         << std::endl;
0121                     break;
0122                 case failed_parse:
0123                     print_indent(get_indent());
0124                     BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl;
0125                     print_indent(--get_indent());
0126                     BOOST_SPIRIT_DEBUG_OUT
0127                         << "</" << rule_name << '>'
0128                         << std::endl;
0129                     break;
0130             }
0131         }
0132     };
0133 }}}
0134 
0135 #endif