1 #ifndef BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
2 #define BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/metaparse/v1/fwd/build_parser.hpp>
10 #include <boost/metaparse/v1/start.hpp>
11 #include <boost/metaparse/v1/is_error.hpp>
12 #include <boost/metaparse/v1/get_remaining.hpp>
14 #include <boost/mpl/if.hpp>
15 #include <boost/mpl/string.hpp>
26 template <class P, class S>
27 class debug_parsing_error
34 using boost::mpl::c_str;
36 typedef display<typename P::template apply<S, start>::type> runner;
38 cout << "Compile-time parsing results" << endl;
39 cout << "----------------------------" << endl;
40 cout << "Input text:" << endl;
41 cout << c_str<S>::type::value << endl;
48 typedef debug_parsing_error type;
50 template <class Result>
55 typedef typename Result::type R;
58 << "Parsing failed:" << std::endl
59 << "line " << get_line<typename R::source_position>::type::value
60 << ", col " << get_col<typename R::source_position>::type::value
62 << R::message::type::get_value() << std::endl;
66 template <class Result>
67 struct display_no_error
73 using boost::mpl::c_str;
75 typedef typename get_remaining<Result>::type remaining_string;
78 << "Parsing was successful. Remaining string is:" << endl
79 << c_str<remaining_string>::type::value << endl;
83 template <class Result>
86 typename is_error<Result>::type,
87 display_error<Result>,
88 display_no_error<Result>
93 // Special case to handle when DebugParsingError is used with build_parser
95 template <class P, class S>
96 class debug_parsing_error<build_parser<P>, S> :
97 debug_parsing_error<P, S>