Home | Libraries | People | FAQ | More |
template <class P, class StateP, class ForwardOp> struct foldl_reject_incomplete_start_with_parser;
This is a parser combinator.
The same as foldl_start_with_parser
,
but once P
rejects the
input, foldl_reject_incomplete_start_with_parser
checks if P
consumes any
characters before rejecting the input. If so, foldl_reject_incomplete_start_with_parser
rejects the input with the same error message this last application of
P
returned. Otherwise
foldl_reject_incomplete_start_with_parser
accepts the input and gives the same result as foldl_start_with_parser
.
Here is a diagram showing how foldl_reject_incomplete_start_with_parser
works by example:
using int_token = token<int_>; using plus_token = token<lit_c<'+'>>; using plus_int = last_of<plus_token, int_token>; using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
Further details can be found in the Introducing foldl_reject_incomplete_start_with_parser section of the User Manual.
#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp>
For any p
parser, pt
class, f
metafunction class taking two arguments, s
compile-time string and pos
source position
foldl_reject_incomplete_start_with_parser<p, pt, f>::apply<s, pos>
is equivalent to
first_of< foldl_start_with_parser<p, pt, f>, fail_at_first_char_expected<p> >::apply<s, pos>
#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> #include <boost/metaparse/lit_c.hpp> #include <boost/metaparse/last_of.hpp> #include <boost/metaparse/token.hpp> #include <boost/metaparse/int_.hpp> #include <boost/metaparse/string.hpp> #include <boost/metaparse/start.hpp> #include <boost/metaparse/get_result.hpp> #include <boost/metaparse/is_error.hpp> #include <boost/mpl/lambda.hpp> #include <boost/mpl/plus.hpp> using namespace boost::metaparse; using int_token = token<int_>; using plus_token = token<lit_c<'+'>>; using plus_int = last_of<plus_token, int_token>; using sum_op = boost::mpl::lambda<boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>>::type; using ints = foldl_reject_incomplete_start_with_parser<plus_int, int_token, sum_op>; static_assert( get_result< ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 + 21"), start> >::type::value == 48, "ints should sum the numbers" ); static_assert( is_error< ints::apply<BOOST_METAPARSE_STRING("11 + 13 + 3 +"), start> >::type::value, "when the last number is missing, it should be an error" );