]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [#letter] |
2 | [section letter] | |
3 | ||
4 | [h1 Synopsis] | |
5 | ||
6 | struct letter; | |
7 | ||
8 | This is a [link parser parser]. | |
9 | ||
10 | [h1 Description] | |
11 | ||
12 | Parser accepting one character in the range `a-z` or `A-Z`. The result of the | |
13 | parser is the accepted character. | |
14 | ||
15 | [h1 Header] | |
16 | ||
17 | #include <boost/metaparse/letter.hpp> | |
18 | ||
19 | [h1 Expression semantics] | |
20 | ||
21 | The following are equivalent: | |
22 | ||
23 | letter | |
24 | ||
25 | accept_when<one_char, util::is_letter<>, error::letter_expected> | |
26 | ||
27 | [h1 Example] | |
28 | ||
29 | #include <boost/metaparse/letter.hpp> | |
30 | #include <boost/metaparse/start.hpp> | |
31 | #include <boost/metaparse/string.hpp> | |
32 | #include <boost/metaparse/is_error.hpp> | |
33 | #include <boost/metaparse/get_result.hpp> | |
34 | ||
35 | using namespace boost::metaparse; | |
36 | ||
37 | static_assert( | |
38 | !is_error<letter::apply<BOOST_METAPARSE_STRING("a"), start>>::type::value, | |
39 | "letter should accept a letter" | |
40 | ); | |
41 | ||
42 | static_assert( | |
43 | is_error<letter::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value, | |
44 | "letter should reject a digit" | |
45 | ); | |
46 | ||
47 | static_assert( | |
48 | get_result< | |
49 | letter::apply<BOOST_METAPARSE_STRING("z"), start> | |
50 | >::type::value == 'z', | |
51 | "the result of parsing should be the character value" | |
52 | ); | |
53 | ||
54 | [endsect] | |
55 |