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
11 #include <boost/mpl/if.hpp>
12 #include <boost/mpl/and.hpp>
13 #include <boost/type_traits/is_convertible.hpp>
17 namespace boost { namespace spirit { namespace x3 { namespace traits
19 ///////////////////////////////////////////////////////////////////////////
20 // generate debug output for lookahead token (character) stream
23 struct token_printer_debug_for_chars
25 template<typename Out, typename Char>
26 static void print(Out& o, Char c)
28 using namespace std; // allow for ADL to find the proper iscntrl
32 case '\a': o << "\\a"; break;
33 case '\b': o << "\\b"; break;
34 case '\f': o << "\\f"; break;
35 case '\n': o << "\\n"; break;
36 case '\r': o << "\\r"; break;
37 case '\t': o << "\\t"; break;
38 case '\v': o << "\\v"; break;
40 if (c >= 0 && c < 127)
43 o << "\\" << std::oct << int(c);
47 o << "\\x" << std::hex << int(c);
50 o << "\\x" << std::hex << int(c);
55 // for token types where the comparison with char constants wouldn't work
56 struct token_printer_debug
58 template<typename Out, typename T>
59 static void print(Out& o, T const& val)
66 template <typename T, typename Enable = void>
67 struct token_printer_debug
70 is_convertible<T, char>, is_convertible<char, T> >
71 , detail::token_printer_debug_for_chars
72 , detail::token_printer_debug>::type
75 template <typename Out, typename T>
76 inline void print_token(Out& out, T const& val)
78 // allow to customize the token printer routine
79 token_printer_debug<T>::print(out, val);