1 [#repeated_reject_incomplete]
2 [section repeated_reject_incomplete]
7 struct repeated_reject_incomplete;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
18 The same as [link repeated `repeated`], but once `P` rejects the input,
19 `repeated_reject_incomplete` checks if `P` consumes any characters before
20 rejecting the input. If so, `repeated_reject_incomplete` rejects the input with
21 the same error message this last application of `P` returned. Otherwise
22 `repeated_reject_incomplete` accepts the input and gives the same result as
23 [link repeated `repeated`].
25 Here is a diagram showing how `repeated_reject_incomplete` works by example:
27 using int_token = token<int_>;
28 using plus_token = token<lit_c<'+'>>;
29 using plus_int = last_of<plus_token, int_token>;
30 using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
32 [$images/metaparse/repeated_reject_incomplete_diag1.png [width 70%]]
36 #include <boost/metaparse/repeated_reject_incomplete.hpp>
38 [h1 Expression semantics]
40 For any `p` parser, `s` compile-time string and `pos` source position
42 repeated_reject_incomplete<p>::apply<s, pos>
46 first_of<repeated<p>, fail_at_first_char_expected<p> >::apply<s, pos>
50 #include <boost/metaparse/repeated_reject_incomplete.hpp>
51 #include <boost/metaparse/lit_c.hpp>
52 #include <boost/metaparse/last_of.hpp>
53 #include <boost/metaparse/token.hpp>
54 #include <boost/metaparse/int_.hpp>
55 #include <boost/metaparse/string.hpp>
56 #include <boost/metaparse/start.hpp>
57 #include <boost/metaparse/get_result.hpp>
58 #include <boost/metaparse/is_error.hpp>
60 #include <boost/mpl/equal.hpp>
61 #include <boost/mpl/vector_c.hpp>
63 using namespace boost::metaparse;
65 using int_token = token<int_>;
66 using plus_token = token<lit_c<'+'>>;
67 using plus_int = last_of<plus_token, int_token>;
69 using ints = repeated_reject_incomplete<plus_int>;
73 boost::mpl::vector_c<int, 13, 3, 21>,
75 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
78 "ints should parse the numbers"
83 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
85 "when the last number is missing, it should be an error"