• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#one_char_except_c]
2[section one_char_except_c]
3
4[h1 Synopsis]
5
6  template <char... Cs>
7  struct one_char_except_c;
8
9This is a [link parser parser].
10
11[table Arguments
12  [[Name]       [Type]]
13  [[`Cs`]       [character values]]
14]
15
16[h1 Description]
17
18`one_char_except_c` accepts one character except any of `Cs`. When the input is
19empty or begins with one of the non-accepted characters, `one_char_except_c`
20rejects the input. Otherwise it accepts the input and the result of parsing is
21the character value.
22
23On compilers, which are not C++11-compliant, the maximum number of characters
24this class can have is the value the macro
25`BOOST_METAPARSE_LIMIT_ONE_CHAR_EXCEPT_SIZE` expands to. Its default value is
2610.
27
28[h1 Header]
29
30  #include <boost/metaparse/one_char_except_c.hpp>
31
32[h1 Expression semantics]
33
34For any `s` compile-time string and `c1`, ..., `cn` characters the following are
35equivalent
36
37  one_char_except_c<c1, ..., cn>::apply<s, pos>
38
39  boost::metaparse::one_char::apply<s, pos>
40
41when `s` is empty or it begins with a character other than `c1`, ..., `cn`.
42Otherwise `one_char_except_c<c1, ..., cn>::appl<s, pos>` returns a parsing
43error.
44
45[h1 Example]
46
47  #include <boost/metaparse/one_char_except_c.hpp>
48  #include <boost/metaparse/lit_c.hpp>
49  #include <boost/metaparse/middle_of.hpp>
50  #include <boost/metaparse/repeated.hpp>
51  #include <boost/metaparse/start.hpp>
52  #include <boost/metaparse/string.hpp>
53  #include <boost/metaparse/get_result.hpp>
54
55  #include <boost/mpl/vector.hpp>
56  #include <boost/mpl/char.hpp>
57  #include <boost/mpl/equal.hpp>
58
59  using namespace boost::metaparse;
60
61  using string_literal_parser =
62    middle_of<lit_c<'"'>, repeated<one_char_except_c<'"'>>, lit_c<'"'>>;
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
82