6 template <class P, class Result, class ErrorMsg>
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`Result`] [[link metaprogramming_value template metaprogramming value]]]
15 [[`ErrorMsg`] [[link parsing_error_message parsing error message]]]
20 `except` accepts the input when `P` rejects it and the result of parsing is the
21 `Result` argument. When `P` accepts the input, `except` rejects it and the
26 #include <boost/metaparse/except.hpp>
28 [h1 Expression semantics]
30 For any `p` parser, `c` class, `msg` parsing error message, `s` compile-time
31 string and `pos` source position the following are equivalent
33 get_result<except<p, c, msg>, s, pos>::type
36 get_remaining<except<p, c, msg>, s, pos>::type
39 get_position<except<p, c, msg>, s, pos>::type
42 when `p` rejects the input. The result of the parser is an error with the error
43 message `msg` otherwise.
47 #include <boost/metaparse/except.hpp>
48 #include <boost/metaparse/int_.hpp>
49 #include <boost/metaparse/string.hpp>
50 #include <boost/metaparse/start.hpp>
51 #include <boost/metaparse/get_result.hpp>
52 #include <boost/metaparse/get_message.hpp>
53 #include <boost/metaparse/define_error.hpp>
55 #include <type_traits>
57 using namespace boost::metaparse;
59 BOOST_METAPARSE_DEFINE_ERROR(
60 number_is_not_allowed,
61 "numbers are not allowed here"
65 except<int_, std::integral_constant<int, 1>, number_is_not_allowed>;
69 except_int::apply<BOOST_METAPARSE_STRING("foo"), start>
71 "it should accept the input when it is not an integer"
76 number_is_not_allowed,
77 get_message<except_int::apply<BOOST_METAPARSE_STRING("13"), start>>::type
79 "it should reject the input when it is an integer"