1 [#foldl_reject_incomplete_start_with_parser]
2 [section foldl_reject_incomplete_start_with_parser]
6 template <class P, class StateP, class ForwardOp>
7 struct foldl_reject_incomplete_start_with_parser;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`StateP`] [[link parser parser]]]
15 [[`ForwardOp`] [[link metafunction_class template metafunction class] taking two arguments]]
20 The same as [link foldl_start_with_parser `foldl_start_with_parser`], but once
21 `P` rejects the input, `foldl_reject_incomplete_start_with_parser` checks if `P`
22 consumes any characters before rejecting the input. If so,
23 `foldl_reject_incomplete_start_with_parser` rejects the input with the same
24 error message this last application of `P` returned. Otherwise
25 `foldl_reject_incomplete_start_with_parser` accepts the input and gives the same
26 result as [link foldl_start_with_parser `foldl_start_with_parser`].
28 Here is a diagram showing how `foldl_reject_incomplete_start_with_parser` works
31 using int_token = token<int_>;
32 using plus_token = token<lit_c<'+'>>;
33 using plus_int = last_of<plus_token, int_token>;
34 using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
36 [$images/metaparse/foldl_reject_incomplete_start_with_parser_diag1.png [width 70%]]
38 Further details can be found in the
39 [link introducing-foldl_reject_incomplete_start_with_parser Introducing foldl_reject_incomplete_start_with_parser]
40 section of the [link manual User Manual].
44 #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp>
46 [h1 Expression semantics]
48 For any `p` parser, `pt` class, `f` metafunction class taking two arguments,
49 `s` compile-time string and `pos` source position
51 foldl_reject_incomplete_start_with_parser<p, pt, f>::apply<s, pos>
56 foldl_start_with_parser<p, pt, f>,
57 fail_at_first_char_expected<p>
62 #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp>
63 #include <boost/metaparse/lit_c.hpp>
64 #include <boost/metaparse/last_of.hpp>
65 #include <boost/metaparse/token.hpp>
66 #include <boost/metaparse/int_.hpp>
67 #include <boost/metaparse/string.hpp>
68 #include <boost/metaparse/start.hpp>
69 #include <boost/metaparse/get_result.hpp>
70 #include <boost/metaparse/is_error.hpp>
72 #include <boost/mpl/lambda.hpp>
73 #include <boost/mpl/plus.hpp>
75 using namespace boost::metaparse;
77 using int_token = token<int_>;
78 using plus_token = token<lit_c<'+'>>;
79 using plus_int = last_of<plus_token, int_token>;
81 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
84 foldl_reject_incomplete_start_with_parser<plus_int, int_token, sum_op>;
88 ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 + 21"), start>
90 "ints should sum the numbers"
95 ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 +"), start>
97 "when the last number is missing, it should be an error"