]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/doc/repeated_reject_incomplete.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / metaparse / doc / repeated_reject_incomplete.qbk
1 [#repeated_reject_incomplete]
2 [section repeated_reject_incomplete]
3
4 [h1 Synopsis]
5
6 template <class P>
7 struct repeated_reject_incomplete;
8
9 This is a [link parser_combinator parser combinator].
10
11 [table Arguments
12 [[Name] [Type]]
13 [[`P`] [[link parser parser]]]
14 ]
15
16 [h1 Description]
17
18 The same as [link repeated `repeated`], but once `P` rejects the input,
19 `repeated_reject_incomplete` checks if `P` consumes any characters before
20 rejecting the input. If so, `repeated_reject_incomplete` rejects the input with
21 the same error message this last application of `P` returned. Otherwise
22 `repeated_reject_incomplete` accepts the input and gives the same result as
23 [link repeated `repeated`].
24
25 Here is a diagram showing how `repeated_reject_incomplete` works by example:
26
27 using int_token = token<int_>;
28 using plus_token = token<lit_c<'+'>>;
29 using plus_int = last_of<plus_token, int_token>;
30 using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
31
32 [$images/metaparse/repeated_reject_incomplete_diag1.png [width 70%]]
33
34 [h1 Header]
35
36 #include <boost/metaparse/repeated_reject_incomplete.hpp>
37
38 [h1 Expression semantics]
39
40 For any `p` parser, `s` compile-time string and `pos` source position
41
42 repeated_reject_incomplete<p>::apply<s, pos>
43
44 is equivalent to
45
46 first_of<repeated<p>, fail_at_first_char_expected<p> >::apply<s, pos>
47
48 [h1 Example]
49
50 #include <boost/metaparse/repeated_reject_incomplete.hpp>
51 #include <boost/metaparse/lit_c.hpp>
52 #include <boost/metaparse/last_of.hpp>
53 #include <boost/metaparse/token.hpp>
54 #include <boost/metaparse/int_.hpp>
55 #include <boost/metaparse/string.hpp>
56 #include <boost/metaparse/start.hpp>
57 #include <boost/metaparse/get_result.hpp>
58 #include <boost/metaparse/is_error.hpp>
59
60 #include <boost/mpl/equal.hpp>
61 #include <boost/mpl/vector_c.hpp>
62
63 using namespace boost::metaparse;
64
65 using int_token = token<int_>;
66 using plus_token = token<lit_c<'+'>>;
67 using plus_int = last_of<plus_token, int_token>;
68
69 using ints = repeated_reject_incomplete<plus_int>;
70
71 static_assert(
72 boost::mpl::equal<
73 boost::mpl::vector_c<int, 13, 3, 21>,
74 get_result<
75 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
76 >::type
77 >::type::value,
78 "ints should parse the numbers"
79 );
80
81 static_assert(
82 is_error<
83 ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
84 >::type::value,
85 "when the last number is missing, it should be an error"
86 );
87
88 [endsect]
89