Home | Libraries | People | FAQ | More |
template <class P1, class P2, class P3> struct middle_of;
This is a parser combinator.
middle_of
applies P1
, P2
and P3
in sequence. It
accepts an input when all of these three parsers accept it. The result
of parsing is the result of P2
.
#include <boost/metaparse/middle_of.hpp>
For any p1
, p2
and p3
parsers
middle_of<p1, p2, p3>
is equivalent to
nth_of<1, p1, p2, p3>
#include <boost/metaparse/middle_of.hpp> #include <boost/metaparse/int_.hpp> #include <boost/metaparse/lit_c.hpp> #include <boost/metaparse/token.hpp> #include <boost/metaparse/start.hpp> #include <boost/metaparse/string.hpp> #include <boost/metaparse/is_error.hpp> #include <boost/metaparse/get_result.hpp> using namespace boost::metaparse; using int_token = token<int_>; using left_paren_token = token<lit_c<'('>>; using right_paren_token = token<lit_c<')'>>; using int_in_parens = middle_of<left_paren_token, int_token, right_paren_token>; static_assert( get_result< int_in_parens::apply<BOOST_METAPARSE_STRING("(13)"), start> >::type::value == 13, "it should return the result of the middle parser" ); static_assert( is_error< int_in_parens::apply<BOOST_METAPARSE_STRING("13"), start> >::type::value, "it should reject the input when there are no parens" ); static_assert( is_error< int_in_parens::apply<BOOST_METAPARSE_STRING("(13"), start> >::type::value, "it should reject the input when there is no closing paren" );