1 [#foldl_reject_incomplete]
2 [section foldl_reject_incomplete]
6 template <class P, class State, class ForwardOp>
7 struct foldl_reject_incomplete;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`State`] [[link metaprogramming_value template metaprogramming value]]]
15 [[`ForwardOp`] [[link metafunction_class template metafunction class] taking two arguments]]
20 The same as [link foldl `foldl`], but once `P` rejects the input,
21 `foldl_reject_incomplete` checks if `P` consumes any characters before rejecting
22 the input. If so, `foldl_reject_incomplete` rejects the input with the same
23 error message this last application of `P` returned. Otherwise
24 `foldl_reject_incomplete` accepts the input and gives the same result as
27 Here is a diagram showing how `foldl_reject_incomplete` works by example:
29 using int_token = token<int_>;
30 using plus_token = token<lit_c<'+'>>;
31 using plus_int = last_of<plus_token, int_token>;
32 using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
34 [$images/metaparse/foldl_reject_incomplete_diag1.png [width 70%]]
38 #include <boost/metaparse/foldl_reject_incomplete.hpp>
40 [h1 Expression semantics]
42 For any `p` parser, `t` class, `f` metafunction class taking two arguments,
43 `s` compile-time string and `pos` source position
45 foldl_reject_incomplete<p, t, f>::apply<s, pos>
49 first_of<foldl<p, t, f>, fail_at_first_char_expected<p> >::apply<s, pos>
53 #include <boost/metaparse/foldl_reject_incomplete.hpp>
54 #include <boost/metaparse/lit_c.hpp>
55 #include <boost/metaparse/last_of.hpp>
56 #include <boost/metaparse/token.hpp>
57 #include <boost/metaparse/int_.hpp>
58 #include <boost/metaparse/string.hpp>
59 #include <boost/metaparse/start.hpp>
60 #include <boost/metaparse/get_result.hpp>
61 #include <boost/metaparse/is_error.hpp>
63 #include <boost/mpl/lambda.hpp>
64 #include <boost/mpl/plus.hpp>
65 #include <boost/mpl/int.hpp>
67 using namespace boost::metaparse;
69 using int_token = token<int_>;
70 using plus_token = token<lit_c<'+'>>;
71 using plus_int = last_of<plus_token, int_token>;
73 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
75 using ints = foldl_reject_incomplete<plus_int, boost::mpl::int_<11>, sum_op>;
79 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
81 "ints should sum the numbers"
86 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
88 "when the last number is missing, it should be an error"