• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#range_c]
2[section range_c]
3
4[h1 Synopsis]
5
6  template <char From, char To>
7  struct range_c;
8
9This is a [link parser parser].
10
11[table Arguments
12  [[Name]   [Type]]
13  [[`From`] [character value]]
14  [[`To`]   [character value]]
15]
16
17[h1 Description]
18
19`range_c` accepts one character in the range `[From..To]`. The result of the
20parser is the accepted character.
21
22[h1 Header]
23
24  #include <boost/metaparse/range_c.hpp>
25
26[h1 Expression semantics]
27
28For any `A`, `B` characters the following are equivalent:
29
30  range_c<A, B>
31
32  accept_when<
33    one_char,
34    util::in_range_c<char, A, B>,
35    errors::unexpected_character
36  >
37
38[h1 Example]
39
40  #include <boost/metaparse/range_c.hpp>
41  #include <boost/metaparse/start.hpp>
42  #include <boost/metaparse/string.hpp>
43  #include <boost/metaparse/is_error.hpp>
44  #include <boost/metaparse/get_result.hpp>
45
46  using namespace boost::metaparse;
47
48  using one_digit = range_c<'0', '9'>;
49
50  static_assert(
51    !is_error<one_digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
52    "one_digit should accept a digit"
53  );
54
55  static_assert(
56    is_error<one_digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
57    "one_digit should reject a value outside of ['0'..'9']"
58  );
59
60  static_assert(
61    get_result<
62      one_digit::apply<BOOST_METAPARSE_STRING("0"), start>
63    >::type::value == '0',
64    "the result of parsing should be the character value"
65  );
66
67[endsect]
68
69