• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#foldl_reject_incomplete1]
2[section foldl_reject_incomplete1]
3
4[h1 Synopsis]
5
6  template <class P, class State, class ForwardOp>
7  struct foldl_reject_incomplete1;
8
9This is a [link parser_combinator parser combinator].
10
11[table Arguments
12  [[Name]        [Type]]
13  [[`P`]         [[link parser parser]]]
14  [[`State`]     [[link metaprogramming_value template metaprogramming value]]]
15  [[`ForwardOp`] [[link metafunction_class template metafunction class] taking two arguments]]
16]
17
18[h1 Description]
19
20The same as [link foldl1 `foldl1`], but once `P` rejects the input,
21`foldl_reject_incomplete1` checks if `P` consumes any characters before
22rejecting the input. If so, `foldl_reject_incomplete1` rejects the input with
23the 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`].
26
27[h1 Header]
28
29  #include <boost/metaparse/foldl_reject_incomplete1.hpp>
30
31[h1 Expression semantics]
32
33For any `p` parser, `t` class, `f` metafunction class taking two arguments,
34`s` compile-time string and `pos` source position
35
36  foldl_reject_incomplete1<p, t, f>::apply<s, pos>
37
38is equivalent to
39
40  first_of<foldl1<p, t, f>, fail_at_first_char_expected<p> >::apply<s, pos>
41
42[h1 Example]
43
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>
53
54  #include <boost/mpl/lambda.hpp>
55  #include <boost/mpl/plus.hpp>
56  #include <boost/mpl/int.hpp>
57
58  using namespace boost::metaparse;
59
60  using int_token = token<int_>;
61  using plus_token = token<lit_c<'+'>>;
62  using plus_int = last_of<plus_token, int_token>;
63  using sum_op =
64    boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
65
66  using ints = foldl_reject_incomplete1<plus_int, boost::mpl::int_<11>, sum_op>;
67
68  static_assert(
69    get_result<
70      ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
71    >::type::value == 48,
72    "ints should sum the numbers"
73  );
74
75  static_assert(
76    is_error<
77      ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
78    >::type::value,
79    "when the last number is missing, it should be an error"
80  );
81
82  static_assert(
83    is_error<ints::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
84    "when no numbers are provided, it should be an error"
85  );
86
87[endsect]
88
89