1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ================================================_==============================*/
8 #if !defined(BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM)
9 #define BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM
15 #include <boost/mpl/if.hpp>
16 #include <boost/mpl/and.hpp>
17 #include <boost/type_traits/is_convertible.hpp>
20 namespace boost { namespace spirit { namespace x3 { namespace traits
22 ///////////////////////////////////////////////////////////////////////////
23 // generate debug output for lookahead token (character) stream
26 struct token_printer_debug_for_chars
28 template<typename Out, typename Char>
29 static void print(Out& o, Char c)
31 using namespace std; // allow for ADL to find the proper iscntrl
35 case '\a': o << "\\a"; break;
36 case '\b': o << "\\b"; break;
37 case '\f': o << "\\f"; break;
38 case '\n': o << "\\n"; break;
39 case '\r': o << "\\r"; break;
40 case '\t': o << "\\t"; break;
41 case '\v': o << "\\v"; break;
43 if (c >= 0 && c < 127 && iscntrl(c))
44 o << "\\" << std::oct << int(c);
51 // for token types where the comparison with char constants wouldn't work
52 struct token_printer_debug
54 template<typename Out, typename T>
55 static void print(Out& o, T const& val)
62 template <typename T, typename Enable = void>
63 struct token_printer_debug
66 is_convertible<T, char>, is_convertible<char, T> >
67 , detail::token_printer_debug_for_chars
68 , detail::token_printer_debug>::type
71 template <typename Out, typename T>
72 inline void print_token(Out& out, T const& val)
74 // allow to customize the token printer routine
75 token_printer_debug<T>::print(out, val);