88 lines
2.3 KiB
Plaintext
88 lines
2.3 KiB
Plaintext
[#repeated_one_of]
|
|
[section repeated_one_of]
|
|
|
|
[h1 Synopsis]
|
|
|
|
template <class... Ps>
|
|
struct repeated_one_of1;
|
|
|
|
[table Arguments
|
|
[[Name] [Type]]
|
|
[[`Ps`] [[link parser parser]s]]
|
|
]
|
|
|
|
This is a [link parser_combinator parser combinator].
|
|
|
|
[h1 Description]
|
|
|
|
It applies the `Ps...` 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 `Ps...` parsers. The result of parsing
|
|
with this [link parser_combinator parser combinator] is a sequence of the
|
|
individual parsing results.
|
|
|
|
When none of the `Ps...` parsers accept the input in the first iteration,
|
|
`repeated_one_of` accepts the input and the result of parsing is an empty
|
|
sequence.
|
|
|
|
On compilers, which are not C++11-compliant, the maximum number of accepted
|
|
parsers is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE` macro. Its default
|
|
value is 20.
|
|
|
|
[h1 Header]
|
|
|
|
#include <boost/metaparse/repeated_one_of.hpp>
|
|
|
|
[h1 Expression semantics]
|
|
|
|
For any `p1`, ..., `pn` parsers
|
|
|
|
repeated_one_of<p1, /* ... */, pn>
|
|
|
|
is equivalent to
|
|
|
|
repeated<one_of<p1, /* ... */, pn>>
|
|
|
|
[h1 Example]
|
|
|
|
#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"
|
|
);
|
|
|
|
[endsect]
|
|
|