6 template <class P, class State, class ForwardOp>
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 `foldl1` applies `P` on the input string repeatedly as long as `P` accepts the
21 input. The result of parsing is equivalent to
22 `boost::mpl::fold<Sequence, State, ForwardOp>`, where `Sequence` is the sequence
23 of the results of the applications of `P`.
25 When `P` rejects the input for the first time, `foldl1` rejects it as well. At
26 least one successful application of `P` is required for `foldl1` to accept the
31 #include <boost/metaparse/foldl1.hpp>
33 [h1 Expression semantics]
35 For any `p` parser, `t` class, `f` metafunction class taking two arguments the
36 following are equivalent:
40 last_of<look_ahead<p>, foldl<p, t, f>>
44 #include <boost/metaparse/foldl1.hpp>
45 #include <boost/metaparse/token.hpp>
46 #include <boost/metaparse/int_.hpp>
47 #include <boost/metaparse/string.hpp>
48 #include <boost/metaparse/start.hpp>
49 #include <boost/metaparse/get_result.hpp>
50 #include <boost/metaparse/is_error.hpp>
52 #include <boost/mpl/lambda.hpp>
53 #include <boost/mpl/plus.hpp>
55 using namespace boost::metaparse;
57 using int_token = token<int_>;
59 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
61 using ints = foldl1<int_token, boost::mpl::int_<0>, sum_op>;
65 ints::apply<BOOST_METAPARSE_STRING("11 13 3 21"), start>
67 "ints should sum the numbers"
71 is_error<ints::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
72 "when no numbers are provided, it should be an error"