#ifndef BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP #define BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include namespace boost { namespace metaparse { namespace v1 { template class debug_parsing_error { public: debug_parsing_error() { using std::cout; using std::endl; using boost::mpl::c_str; typedef display::type> runner; cout << "Compile-time parsing results" << endl; cout << "----------------------------" << endl; cout << "Input text:" << endl; cout << c_str::type::value << endl; cout << endl; runner::run(); std::exit(0); } typedef debug_parsing_error type; private: template struct display_error { static void run() { typedef typename Result::type R; std::cout << "Parsing failed:" << std::endl << "line " << get_line::type::value << ", col " << get_col::type::value << ": " << R::message::type::get_value() << std::endl; } }; template struct display_no_error { static void run() { using std::cout; using std::endl; using boost::mpl::c_str; typedef typename get_remaining::type remaining_string; cout << "Parsing was successful. Remaining string is:" << endl << c_str::type::value << endl; } }; template struct display : boost::mpl::if_< typename is_error::type, display_error, display_no_error >::type {}; }; // Special case to handle when DebugParsingError is used with build_parser // (it shouldn't be) template class debug_parsing_error, S> : debug_parsing_error {}; } } } #endif