• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#repeated_one_of]
2[section repeated_one_of]
3
4[h1 Synopsis]
5
6  template <class... Ps>
7  struct repeated_one_of1;
8
9[table Arguments
10  [[Name] [Type]]
11  [[`Ps`] [[link parser parser]s]]
12]
13
14This is a [link parser_combinator parser combinator].
15
16[h1 Description]
17
18It applies the `Ps...` parsers repeatedly as long as any of them accepts the
19input. In each iteration the parsers are tried in order and the first one
20accepting the input is used, therefore in case of ambiguous grammars the result
21of parsing depends on the order of the `Ps...` parsers. The result of parsing
22with this [link parser_combinator parser combinator] is a sequence of the
23individual parsing results.
24
25When none of the `Ps...` parsers accept the input in the first iteration,
26`repeated_one_of` accepts the input and the result of parsing is an empty
27sequence.
28
29On compilers, which are not C++11-compliant, the maximum number of accepted
30parsers is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE` macro. Its default
31value is 20.
32
33[h1 Header]
34
35  #include <boost/metaparse/repeated_one_of.hpp>
36
37[h1 Expression semantics]
38
39For any `p1`, ..., `pn` parsers
40
41  repeated_one_of<p1, /* ... */, pn>
42
43is equivalent to
44
45  repeated<one_of<p1, /* ... */, pn>>
46
47[h1 Example]
48
49  #include <boost/metaparse/repeated_one_of.hpp>
50  #include <boost/metaparse/lit_c.hpp>
51  #include <boost/metaparse/start.hpp>
52  #include <boost/metaparse/string.hpp>
53  #include <boost/metaparse/get_result.hpp>
54
55  #include <boost/mpl/equal.hpp>
56  #include <boost/mpl/vector.hpp>
57  #include <boost/mpl/char.hpp>
58
59  using namespace boost::metaparse;
60
61  using as_and_bs = repeated_one_of<lit_c<'a'>, lit_c<'b'>>;
62
63  static_assert(
64    boost::mpl::equal<
65      get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("abaab"), start>>::type,
66      boost::mpl::vector<
67        boost::mpl::char_<'a'>,
68        boost::mpl::char_<'b'>,
69        boost::mpl::char_<'a'>,
70        boost::mpl::char_<'a'>,
71        boost::mpl::char_<'b'>
72      >
73    >::type::value,
74    "the result of parsing should be the list of results"
75  );
76
77  static_assert(
78    boost::mpl::equal<
79      get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("x"), start>>::type,
80      boost::mpl::vector<>
81    >::type::value,
82    "repeated_one_of should accept the input when it"
83    " can't parse anything with digit_val"
84  );
85
86[endsect]
87
88