1 [#fail_at_first_char_expected]
2 [section fail_at_first_char_expected]
7 struct fail_at_first_char_expected;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
18 It tries to parse the input using `P`. When `P` rejects the input without
19 consuming any character, `fail_at_first_char_expected` accepts the input.
20 Otherwise (when `P` accepts the input or when it consumes characters before
21 rejecting the input) `fail_at_first_char_expected` rejects the input.
25 #include <boost/metaparse/fail_at_first_char_expected.hpp>
27 [h1 Expression semantics]
29 For any `p` parser, `s` compile-time string and `pos` source position:
31 When `is_error<p::apply<s, pos>>::type` is false, the following are equivalent:
33 fail_at_first_char_expected<p>::apply<s, pos>::type
34 reject<error::expected_to_fail, pos>
36 When `is_error<p::apply<s, pos>>::type` is true and
37 `boost::mpl::equal_to<pos, get_position<p::apply<s, pos>>::type>::type` is also
38 true, the following are equivalent:
40 get_remaining<except<p, c, msg>, s, pos>::type
41 accept</* unspecified */, s, pos>
43 Otherwise the following are equivalent:
45 get_remaining<except<p, c, msg>, s, pos>::type
46 p::apply<s, pos>::type
50 #include <boost/metaparse/fail_at_first_char_expected.hpp>
51 #include <boost/metaparse/int_.hpp>
52 #include <boost/metaparse/lit_c.hpp>
53 #include <boost/metaparse/foldl_start_with_parser.hpp>
54 #include <boost/metaparse/first_of.hpp>
55 #include <boost/metaparse/last_of.hpp>
56 #include <boost/metaparse/string.hpp>
57 #include <boost/metaparse/start.hpp>
58 #include <boost/metaparse/is_error.hpp>
59 #include <boost/metaparse/get_result.hpp>
61 #include <boost/mpl/lambda.hpp>
62 #include <boost/mpl/plus.hpp>
64 using namespace boost::metaparse;
66 using plus_int = last_of<lit_c<'+'>, int_>;
70 foldl_start_with_parser<
73 boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type
75 fail_at_first_char_expected<plus_int>
80 plus_exp::apply<BOOST_METAPARSE_STRING("1+2+3"), start>
82 "it should accept the input when it is a list of '+' separated ints"
87 plus_exp::apply<BOOST_METAPARSE_STRING("1+2+3+"), start>
89 "it should reject the input when it has an extra +"