]>
Commit | Line | Data |
---|---|---|
1 | [#one_char_except] | |
2 | [section one_char_except] | |
3 | ||
4 | [h1 Synopsis] | |
5 | ||
6 | template <class C1, class C2, /* ... */, class Cn> | |
7 | struct one_char_except; | |
8 | ||
9 | This is a [link parser parser]. | |
10 | ||
11 | [table Arguments | |
12 | [[Name] [Type]] | |
13 | [[`C1`..`Cn`] [[link boxed_value boxed] character values]] | |
14 | ] | |
15 | ||
16 | [h1 Description] | |
17 | ||
18 | `one_char_except` accepts one character except any of `C1` ... `Cn`. When the | |
19 | input is empty or begins with one of the non-accepted characters, | |
20 | `one_char_except` rejects the input. Otherwise it accepts the input and the | |
21 | result of parsing is the character value. | |
22 | ||
23 | The maximum number of template arguments this class can have is the value the | |
24 | macro `BOOST_METAPARSE_LIMIT_ONE_CHAR_EXCEPT_SIZE` expands to. Its default value | |
25 | is 10. | |
26 | ||
27 | [h1 Header] | |
28 | ||
29 | #include <boost/metaparse/one_char_except.hpp> | |
30 | ||
31 | [h1 Expression semantics] | |
32 | ||
33 | For any `c1`, ..., `cn` boxed characters the following are equivalent | |
34 | ||
35 | one_char_except<c1, ..., cn> | |
36 | ||
37 | one_char_except_c<c1::type::value, ..., cn::type::value> | |
38 | ||
39 | [h1 Example] | |
40 | ||
41 | #include <boost/metaparse/one_char_except.hpp> | |
42 | #include <boost/metaparse/lit_c.hpp> | |
43 | #include <boost/metaparse/middle_of.hpp> | |
44 | #include <boost/metaparse/repeated.hpp> | |
45 | #include <boost/metaparse/start.hpp> | |
46 | #include <boost/metaparse/string.hpp> | |
47 | #include <boost/metaparse/get_result.hpp> | |
48 | ||
49 | #include <boost/mpl/vector.hpp> | |
50 | #include <boost/mpl/char.hpp> | |
51 | #include <boost/mpl/equal.hpp> | |
52 | ||
53 | #include <type_traits> | |
54 | ||
55 | using namespace boost::metaparse; | |
56 | ||
57 | using string_literal_parser = | |
58 | middle_of< | |
59 | lit_c<'"'>, | |
60 | repeated<one_char_except<std::integral_constant<char, '"'>>>, | |
61 | lit_c<'"'> | |
62 | >; | |
63 | ||
64 | static_assert( | |
65 | boost::mpl::equal< | |
66 | boost::mpl::vector< | |
67 | boost::mpl::char_<'h'>, | |
68 | boost::mpl::char_<'e'>, | |
69 | boost::mpl::char_<'l'>, | |
70 | boost::mpl::char_<'l'>, | |
71 | boost::mpl::char_<'o'> | |
72 | >, | |
73 | get_result< | |
74 | string_literal_parser::apply<BOOST_METAPARSE_STRING("\"hello\""), start> | |
75 | >::type | |
76 | >::type::value, | |
77 | "it should return the content of the string literal" | |
78 | ); | |
79 | ||
80 | [endsect] | |
81 |