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