]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/doc/foldl_reject_incomplete_start_with_parser.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / metaparse / doc / foldl_reject_incomplete_start_with_parser.qbk
1 [#foldl_reject_incomplete_start_with_parser]
2 [section foldl_reject_incomplete_start_with_parser]
3
4 [h1 Synopsis]
5
6 template <class P, class StateP, class ForwardOp>
7 struct foldl_reject_incomplete_start_with_parser;
8
9 This is a [link parser_combinator parser combinator].
10
11 [table Arguments
12 [[Name] [Type]]
13 [[`P`] [[link parser parser]]]
14 [[`StateP`] [[link parser parser]]]
15 [[`ForwardOp`] [[link metafunction_class template metafunction class] taking two arguments]]
16 ]
17
18 [h1 Description]
19
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`].
27
28 Here is a diagram showing how `foldl_reject_incomplete_start_with_parser` works
29 by example:
30
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;
35
36 [$images/metaparse/foldl_reject_incomplete_start_with_parser_diag1.png [width 70%]]
37
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].
41
42 [h1 Header]
43
44 #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp>
45
46 [h1 Expression semantics]
47
48 For any `p` parser, `pt` class, `f` metafunction class taking two arguments,
49 `s` compile-time string and `pos` source position
50
51 foldl_reject_incomplete_start_with_parser<p, pt, f>::apply<s, pos>
52
53 is equivalent to
54
55 first_of<
56 foldl_start_with_parser<p, pt, f>,
57 fail_at_first_char_expected<p>
58 >::apply<s, pos>
59
60 [h1 Example]
61
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>
71
72 #include <boost/mpl/lambda.hpp>
73 #include <boost/mpl/plus.hpp>
74
75 using namespace boost::metaparse;
76
77 using int_token = token<int_>;
78 using plus_token = token<lit_c<'+'>>;
79 using plus_int = last_of<plus_token, int_token>;
80 using sum_op =
81 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type;
82
83 using ints =
84 foldl_reject_incomplete_start_with_parser<plus_int, int_token, sum_op>;
85
86 static_assert(
87 get_result<
88 ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 + 21"), start>
89 >::type::value == 48,
90 "ints should sum the numbers"
91 );
92
93 static_assert(
94 is_error<
95 ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 +"), start>
96 >::type::value,
97 "when the last number is missing, it should be an error"
98 );
99
100 [endsect]
101