|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63756 - in trunk/boost/spirit/home: lex/lexer/lexertl qi/nonterminal support
From: hartmut.kaiser_at_[hidden]
Date: 2010-07-08 14:13:02
Author: hkaiser
Date: 2010-07-08 14:13:01 EDT (Thu, 08 Jul 2010)
New Revision: 63756
URL: http://svn.boost.org/trac/boost/changeset/63756
Log:
Spirit: integrated lexer with Qi's debug facilities
Text files modified:
trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp | 17 ++++
trunk/boost/spirit/home/qi/nonterminal/simple_trace.hpp | 53 ---------------
trunk/boost/spirit/home/support/attributes.hpp | 137 ++++++++++++++++++++++++++++++---------
trunk/boost/spirit/home/support/attributes_fwd.hpp | 16 ++++
4 files changed, 137 insertions(+), 86 deletions(-)
Modified: trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp 2010-07-08 14:13:01 EDT (Thu, 08 Jul 2010)
@@ -543,6 +543,23 @@
}
};
+ ///////////////////////////////////////////////////////////////////////////
+ // Overload debug output for a single token, this integrates lexer tokens
+ // with Qi's simple_trace debug facilities
+ template <typename Iterator, typename Attribute, typename HasState>
+ struct token_printer_debug<lex::lexertl::token<Iterator, Attribute, HasState> >
+ {
+ typedef lex::lexertl::token<Iterator, Attribute, HasState> token_type;
+
+ template <typename Out>
+ static void print(Out& out, token_type const& val)
+ {
+ out << '<';
+ spirit::traits::print_token(out, val.value());
+ out << '>';
+ }
+ };
+
}}}
#endif
Modified: trunk/boost/spirit/home/qi/nonterminal/simple_trace.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/simple_trace.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/simple_trace.hpp 2010-07-08 14:13:01 EDT (Thu, 08 Jul 2010)
@@ -40,62 +40,11 @@
{
namespace detail
{
- struct token_printer_aux_for_chars
- {
- template<typename Char>
- static void print(std::ostream& o, Char c)
- {
- using namespace std; // allow for ADL to find the proper iscntrl
-
- if (c == static_cast<Char>('\a'))
- o << "\\a";
- else if (c == static_cast<Char>('\b'))
- o << "\\b";
- else if (c == static_cast<Char>('\f'))
- o << "\\f";
- else if (c == static_cast<Char>('\n'))
- o << "\\n";
- else if (c == static_cast<Char>('\r'))
- o << "\\r";
- else if (c == static_cast<Char>('\t'))
- o << "\\t";
- else if (c == static_cast<Char>('\v'))
- o << "\\v";
- else if (c < 127 && iscntrl(c))
- o << "\\" << std::oct << static_cast<int>(c);
- else
- o << static_cast<char>(c);
- }
- };
-
- // for token types where the comparison with char constants wouldn't work
- struct token_printer_aux_for_other_types
- {
- template<typename Char>
- static void print(std::ostream& o, Char c)
- {
- o << c;
- }
- };
-
- template <typename Char>
- struct token_printer_aux
- : mpl::if_<
- mpl::and_<
- is_convertible<Char, char>, is_convertible<char, Char> >
- , token_printer_aux_for_chars
- , token_printer_aux_for_other_types>::type
- {};
-
template<typename Char>
inline void token_printer(std::ostream& o, Char c)
{
// allow to customize the token printer routine
-#if !defined(BOOST_SPIRIT_DEBUG_TOKEN_PRINTER)
- token_printer_aux<Char>::print(o, c);
-#else
- BOOST_SPIRIT_DEBUG_TOKEN_PRINTER(o, c);
-#endif
+ spirit::traits::print_token(o, c);
}
}
Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2010-07-08 14:13:01 EDT (Thu, 08 Jul 2010)
@@ -794,31 +794,6 @@
namespace detail
{
- // for stl container data types
- template <typename Out, typename T>
- void print_attribute_impl(Out& out, T const& val, mpl::true_)
- {
- out << '[';
- if (!val.empty())
- {
- for (typename T::const_iterator i = val.begin(); i != val.end(); ++i)
- {
- if (i != val.begin())
- out << ", ";
- print_attribute(out, *i);
- }
-
- }
- out << ']';
- }
-
- // for non-fusion data types
- template <typename Out, typename T>
- void print_attribute_impl2(Out& out, T const& val, mpl::false_)
- {
- out << val;
- }
-
template <typename Out>
struct print_fusion_sequence
{
@@ -840,29 +815,64 @@
Out& out;
mutable bool is_first;
};
+ }
+
+ template <typename Out, typename T, typename Enable>
+ struct print_attribute_debug
+ {
+ // for stl container data types
+ template <typename T_>
+ static void call_impl(Out& out, T_ const& val, mpl::true_)
+ {
+ out << '[';
+ if (!val.empty())
+ {
+ for (typename T_::const_iterator i = val.begin(); i != val.end(); ++i)
+ {
+ if (i != val.begin())
+ out << ", ";
+ print_attribute(out, *i);
+ }
+
+ }
+ out << ']';
+ }
+
+ // for non-fusion data types
+ template <typename T_>
+ static void call_impl2(Out& out, T_ const& val, mpl::false_)
+ {
+ out << val;
+ }
// for fusion data types
- template <typename Out, typename T>
- void print_attribute_impl2(Out& out, T const& val, mpl::true_)
+ template <typename T_>
+ static void call_impl2(Out& out, T_ const& val, mpl::true_)
{
out << '[';
- fusion::for_each(val, print_fusion_sequence<Out>(out));
+ fusion::for_each(val, detail::print_fusion_sequence<Out>(out));
out << ']';
}
// for non-stl container data types
- template <typename Out, typename T>
- void print_attribute_impl(Out& out, T const& val, mpl::false_)
+ template <typename T_>
+ static void call_impl(Out& out, T_ const& val, mpl::false_)
{
- print_attribute_impl2(out, val, fusion::traits::is_sequence<T>());
+ call_impl2(out, val, fusion::traits::is_sequence<T_>());
}
- }
+
+ // main entry point
+ static void call(Out& out, T const& val)
+ {
+ call_impl(out, val
+ , mpl::and_<is_container<T>, not_is_variant<T, void> >());
+ }
+ };
template <typename Out, typename T>
inline void print_attribute(Out& out, T const& val)
{
- detail::print_attribute_impl(out, val,
- mpl::and_<is_container<T>, not_is_variant<T, void> >());
+ print_attribute_debug<Out, T>::call(out, val);
}
template <typename Out, typename T>
@@ -873,6 +883,65 @@
else
out << "<empty>";
}
+
+ ///////////////////////////////////////////////////////////////////////////
+ // generate debug output for lookahead token (character) stream
+ namespace detail
+ {
+ struct token_printer_debug_for_chars
+ {
+ template<typename Out, typename Char>
+ static void print(Out& o, Char c)
+ {
+ using namespace std; // allow for ADL to find the proper iscntrl
+
+ if (c == static_cast<Char>('\a'))
+ o << "\\a";
+ else if (c == static_cast<Char>('\b'))
+ o << "\\b";
+ else if (c == static_cast<Char>('\f'))
+ o << "\\f";
+ else if (c == static_cast<Char>('\n'))
+ o << "\\n";
+ else if (c == static_cast<Char>('\r'))
+ o << "\\r";
+ else if (c == static_cast<Char>('\t'))
+ o << "\\t";
+ else if (c == static_cast<Char>('\v'))
+ o << "\\v";
+ else if (c < 127 && iscntrl(c))
+ o << "\\" << std::oct << static_cast<int>(c);
+ else
+ o << static_cast<char>(c);
+ }
+ };
+
+ // for token types where the comparison with char constants wouldn't work
+ struct token_printer_debug
+ {
+ template<typename Out, typename T>
+ static void print(Out& o, T const& val)
+ {
+ o << val;
+ }
+ };
+ }
+
+ template <typename T, typename Enable>
+ struct token_printer_debug
+ : mpl::if_<
+ mpl::and_<
+ is_convertible<T, char>, is_convertible<char, T> >
+ , detail::token_printer_debug_for_chars
+ , detail::token_printer_debug>::type
+ {};
+
+ template <typename Out, typename T>
+ inline void print_token(Out& out, T const& val)
+ {
+ // allow to customize the token printer routine
+ token_printer_debug<T>::print(out, val);
+ }
}}}
///////////////////////////////////////////////////////////////////////////////
Modified: trunk/boost/spirit/home/support/attributes_fwd.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes_fwd.hpp (original)
+++ trunk/boost/spirit/home/support/attributes_fwd.hpp 2010-07-08 14:13:01 EDT (Thu, 08 Jul 2010)
@@ -162,6 +162,22 @@
template <typename Iterator, typename Enable = void>
struct compare_iterators;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Print the given attribute of type T to the stream given as Out
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Out, typename T, typename Enable = void>
+ struct print_attribute_debug;
+
+ template <typename Out, typename T>
+ void print_attribute(Out& out, T const& val);
+
+ template <typename Char, typename Enable = void>
+ struct token_printer_debug;
+
+ template<typename Out, typename T>
+ void print_token(Out& out, T const& val);
+
}}}
#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk