• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#lit]
2[section lit]
3
4[h1 Synopsis]
5
6  template <class C>
7  struct lit;
8
9This is a [link parser parser].
10
11[table Arguments
12  [[Name] [Type]]
13  [[`C`]  [[link boxed_value boxed] character value]]
14]
15
16[h1 Description]
17
18Parser accepting only the `C` character. The result of parsing is the accepted
19character.
20
21[h1 Header]
22
23  #include <boost/metaparse/lit.hpp>
24
25[h1 Expression semantics]
26
27For any `c` boxed character the following are equivalent:
28
29  lit<c>
30
31  accept_when<
32    one_char,
33    boost::mpl::lambda<boost::mpl::equal_to<boost::mpl::_1, c>>::type,
34    error::literal_expected<c::type::value>
35  >
36
37[h1 Example]
38
39  #include <boost/metaparse/lit.hpp>
40  #include <boost/metaparse/start.hpp>
41  #include <boost/metaparse/string.hpp>
42  #include <boost/metaparse/is_error.hpp>
43  #include <boost/metaparse/get_result.hpp>
44
45  #include <type_traits>
46
47  using namespace boost::metaparse;
48
49  static_assert(
50    is_error<
51      lit<std::integral_constant<char, 'x'>>
52        ::apply<BOOST_METAPARSE_STRING("a"), start>
53    >::type::value,
54    "a different character should be an error"
55  );
56
57  static_assert(
58    is_error<
59      lit<std::integral_constant<char, 'x'>>
60        ::apply<BOOST_METAPARSE_STRING(""), start>
61    >::type::value,
62    "empty input should be an error"
63  );
64
65  static_assert(
66    get_result<
67      lit<std::integral_constant<char, 'x'>>
68        ::apply<BOOST_METAPARSE_STRING("x"), start>
69    >::type::value == 'x',
70    "result of parsing should be the accepted character"
71  );
72
73[endsect]
74
75