Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:38

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 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_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM)
0009 #define BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM
0010 
0011 #include <boost/mpl/if.hpp>
0012 #include <boost/mpl/and.hpp>
0013 #include <boost/type_traits/is_convertible.hpp>
0014 #include <cctype>
0015 #include <ios>
0016 
0017 namespace boost { namespace spirit { namespace x3 { namespace traits
0018 {
0019     ///////////////////////////////////////////////////////////////////////////
0020     // generate debug output for lookahead token (character) stream
0021     namespace detail
0022     {
0023         struct token_printer_debug_for_chars
0024         {
0025             template<typename Out, typename Char>
0026             static void print(Out& o, Char c)
0027             {
0028                 using namespace std;    // allow for ADL to find the proper iscntrl
0029 
0030                 switch (c)
0031                 {
0032                     case '\a': o << "\\a"; break;
0033                     case '\b': o << "\\b"; break;
0034                     case '\f': o << "\\f"; break;
0035                     case '\n': o << "\\n"; break;
0036                     case '\r': o << "\\r"; break;
0037                     case '\t': o << "\\t"; break;
0038                     case '\v': o << "\\v"; break;
0039                     default:
0040                         if (c >= 0 && c < 127)
0041                         {
0042                           if (iscntrl(c))
0043                             o << "\\" << std::oct << int(c);
0044                           else if (isprint(c))
0045                             o << char(c);
0046                           else
0047                             o << "\\x" << std::hex << int(c);
0048                         }
0049                         else
0050                           o << "\\x" << std::hex << int(c);
0051                 }
0052             }
0053         };
0054 
0055         // for token types where the comparison with char constants wouldn't work
0056         struct token_printer_debug
0057         {
0058             template<typename Out, typename T>
0059             static void print(Out& o, T const& val)
0060             {
0061                 o << val;
0062             }
0063         };
0064     }
0065 
0066     template <typename T, typename Enable = void>
0067     struct token_printer_debug
0068       : mpl::if_<
0069             mpl::and_<
0070                 is_convertible<T, char>, is_convertible<char, T> >
0071           , detail::token_printer_debug_for_chars
0072           , detail::token_printer_debug>::type
0073     {};
0074 
0075     template <typename Out, typename T>
0076     inline void print_token(Out& out, T const& val)
0077     {
0078         // allow to customize the token printer routine
0079         token_printer_debug<T>::print(out, val);
0080     }
0081 }}}}
0082 
0083 #endif