one_char_except_c.qbk 2.1 KB

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