Home | Libraries | People | FAQ | More |
template <class P1, class P2, /* ... */, class Pn> struct repeated_one_of1;
This is a parser combinator.
It applies the P1
...
Pn
parsers repeatedly as
long as any of them accepts the input. In each iteration the parsers are
tried in order and the first one accepting the input is used, therefore
in case of ambiguous grammars the result of parsing depends on the order
of the P1
... Pn
parsers. The result of parsing with
this parser combinator is a sequence
of the individual parsing results.
When none of the P1
...
Pn
parsers accept the input
in the first iteration, repeated_one_of
accepts the input and the result of parsing is an empty sequence.
The maximum number of accepted parsers is defined by the BOOST_METAPARSE_LIMIT_ONE_OF_SIZE
macro.
Its default value is 20.
#include <boost/metaparse/repeated_one_of.hpp>
For any p1
, ..., pn
parsers
repeated_one_of<p1, /* ... */, pn>
is equivalent to
repeated<one_of<p1, /* ... */, pn>>
#include <boost/metaparse/repeated_one_of.hpp> #include <boost/metaparse/lit_c.hpp> #include <boost/metaparse/start.hpp> #include <boost/metaparse/string.hpp> #include <boost/metaparse/get_result.hpp> #include <boost/mpl/equal.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/char.hpp> using namespace boost::metaparse; using as_and_bs = repeated_one_of<lit_c<'a'>, lit_c<'b'>>; static_assert( boost::mpl::equal< get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("abaab"), start>>::type, boost::mpl::vector< boost::mpl::char_<'a'>, boost::mpl::char_<'b'>, boost::mpl::char_<'a'>, boost::mpl::char_<'a'>, boost::mpl::char_<'b'> > >::type::value, "the result of parsing should be the list of results" ); static_assert( boost::mpl::equal< get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("x"), start>>::type, boost::mpl::vector<> >::type::value, "repeated_one_of should accept the input when it" " can't parse anything with digit_val" );