1 [#foldl_reject_incomplete1]
2 [section foldl_reject_incomplete1]
6 template <class P, class State, class ForwardOp>
7 struct foldl_reject_incomplete1;
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 foldl1 `foldl1`], but once `P` rejects the input,
21 `foldl_reject_incomplete1` checks if `P` consumes any characters before
22 rejecting the input. If so, `foldl_reject_incomplete1` rejects the input with
23 the same error message this last application of `P` returned. Otherwise
24 `foldl_reject_incomplete1` accepts the input and gives the same result as
25 [link foldl1 `foldl1`].
29 #include <boost/metaparse/foldl_reject_incomplete1.hpp>
31 [h1 Expression semantics]
33 For any `p` parser, `t` class, `f` metafunction class taking two arguments,
34 `s` compile-time string and `pos` source position
36 foldl_reject_incomplete1<p, t, f>::apply<s, pos>
40 first_of<foldl1<p, t, f>, fail_at_first_char_expected<p> >::apply<s, pos>
44 #include <boost/metaparse/foldl_reject_incomplete1.hpp>
45 #include <boost/metaparse/lit_c.hpp>
46 #include <boost/metaparse/last_of.hpp>
47 #include <boost/metaparse/token.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/is_error.hpp>
54 #include <boost/mpl/lambda.hpp>
55 #include <boost/mpl/plus.hpp>
56 #include <boost/mpl/int.hpp>
58 using namespace boost::metaparse;
60 using int_token = token<int_>;
61 using plus_token = token<lit_c<'+'>>;
62 using plus_int = last_of<plus_token, int_token>;
64 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
66 using ints = foldl_reject_incomplete1<plus_int, boost::mpl::int_<11>, sum_op>;
70 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
72 "ints should sum the numbers"
77 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
79 "when the last number is missing, it should be an error"
83 is_error<ints::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
84 "when no numbers are provided, it should be an error"