]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/metaparse/v1/debug_parsing_error.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / metaparse / v1 / debug_parsing_error.hpp
1 #ifndef BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
2 #define BOOST_METAPARSE_V1_DEBUG_PARSING_ERROR_HPP
3
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)
8
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>
13
14 #include <boost/mpl/if.hpp>
15 #include <boost/mpl/string.hpp>
16
17 #include <iostream>
18 #include <cstdlib>
19
20 namespace boost
21 {
22 namespace metaparse
23 {
24 namespace v1
25 {
26 template <class P, class S>
27 class debug_parsing_error
28 {
29 public:
30 debug_parsing_error()
31 {
32 using std::cout;
33 using std::endl;
34 using boost::mpl::c_str;
35
36 typedef display<typename P::template apply<S, start>::type> runner;
37
38 cout << "Compile-time parsing results" << endl;
39 cout << "----------------------------" << endl;
40 cout << "Input text:" << endl;
41 cout << c_str<S>::type::value << endl;
42 cout << endl;
43 runner::run();
44
45 std::exit(0);
46 }
47
48 typedef debug_parsing_error type;
49 private:
50 template <class Result>
51 struct display_error
52 {
53 static void run()
54 {
55 typedef typename Result::type R;
56
57 std::cout
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
61 << ": "
62 << R::message::type::get_value() << std::endl;
63 }
64 };
65
66 template <class Result>
67 struct display_no_error
68 {
69 static void run()
70 {
71 using std::cout;
72 using std::endl;
73 using boost::mpl::c_str;
74
75 typedef typename get_remaining<Result>::type remaining_string;
76
77 cout
78 << "Parsing was successful. Remaining string is:" << endl
79 << c_str<remaining_string>::type::value << endl;
80 }
81 };
82
83 template <class Result>
84 struct display :
85 boost::mpl::if_<
86 typename is_error<Result>::type,
87 display_error<Result>,
88 display_no_error<Result>
89 >::type
90 {};
91 };
92
93 // Special case to handle when DebugParsingError is used with build_parser
94 // (it shouldn't be)
95 template <class P, class S>
96 class debug_parsing_error<build_parser<P>, S> :
97 debug_parsing_error<P, S>
98 {};
99 }
100 }
101 }
102
103 #endif
104
105