Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:49

0001 #ifndef BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
0002 #define BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
0003 
0004 // Copyright Abel Sinkovics (abel@sinkovics.hu)  2011.
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #include <boost/metaparse/v1/fwd/build_parser.hpp>
0010 #include <boost/metaparse/v1/start.hpp>
0011 #include <boost/metaparse/v1/is_error.hpp>
0012 #include <boost/metaparse/v1/get_remaining.hpp>
0013 
0014 #include <boost/mpl/if.hpp>
0015 #include <boost/mpl/string.hpp>
0016 
0017 #include <iostream>
0018 #include <cstdlib>
0019 
0020 namespace boost
0021 {
0022   namespace metaparse
0023   {
0024     namespace v1
0025     {
0026       template <class P, class S>
0027       class debug_parsing_error
0028       {
0029       public:
0030         debug_parsing_error()
0031         {
0032           using std::cout;
0033           using std::endl;
0034           using boost::mpl::c_str;
0035         
0036           typedef display<typename P::template apply<S, start>::type> runner;
0037             
0038           cout << "Compile-time parsing results" << endl;
0039           cout << "----------------------------" << endl;
0040           cout << "Input text:" << endl;
0041           cout << c_str<S>::type::value << endl;
0042           cout << endl;
0043           runner::run();
0044           
0045           std::exit(0);
0046         }
0047       
0048         typedef debug_parsing_error type;
0049       private:
0050         template <class Result>
0051         struct display_error
0052         {
0053           static void run()
0054           {
0055             typedef typename Result::type R;
0056 
0057             std::cout
0058               << "Parsing failed:" << std::endl
0059               << "line " << get_line<typename R::source_position>::type::value
0060               << ", col " << get_col<typename R::source_position>::type::value
0061               << ": "
0062               << R::message::type::get_value() << std::endl;
0063           }
0064         };
0065         
0066         template <class Result>
0067         struct display_no_error
0068         {
0069           static void run()
0070           {
0071             using std::cout;
0072             using std::endl;
0073             using boost::mpl::c_str;
0074             
0075             typedef typename get_remaining<Result>::type remaining_string;
0076             
0077             cout
0078               << "Parsing was successful. Remaining string is:" << endl
0079               << c_str<remaining_string>::type::value << endl;
0080           }
0081         };
0082 
0083         template <class Result>
0084         struct display :
0085           boost::mpl::if_<
0086             typename is_error<Result>::type,
0087             display_error<Result>,
0088             display_no_error<Result>
0089           >::type
0090         {};
0091       };
0092 
0093       // Special case to handle when DebugParsingError is used with build_parser
0094       // (it shouldn't be)
0095       template <class P, class S>
0096       class debug_parsing_error<build_parser<P>, S> :
0097         debug_parsing_error<P, S>
0098       {};
0099     }
0100   }
0101 }
0102 
0103 #endif
0104 
0105