one_char_except.qbk 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. [#one_char_except]
  2. [section one_char_except]
  3. [h1 Synopsis]
  4. template <class... Cs>
  5. struct one_char_except;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Cs`] [[link boxed_value boxed] character values]]
  10. ]
  11. [h1 Description]
  12. `one_char_except` 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`
  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.hpp>
  22. [h1 Expression semantics]
  23. For any `c1`, ..., `cn` boxed characters the following are equivalent
  24. one_char_except<c1, ..., cn>
  25. one_char_except_c<c1::type::value, ..., cn::type::value>
  26. [h1 Example]
  27. #include <boost/metaparse/one_char_except.hpp>
  28. #include <boost/metaparse/lit_c.hpp>
  29. #include <boost/metaparse/middle_of.hpp>
  30. #include <boost/metaparse/repeated.hpp>
  31. #include <boost/metaparse/start.hpp>
  32. #include <boost/metaparse/string.hpp>
  33. #include <boost/metaparse/get_result.hpp>
  34. #include <boost/mpl/vector.hpp>
  35. #include <boost/mpl/char.hpp>
  36. #include <boost/mpl/equal.hpp>
  37. #include <type_traits>
  38. using namespace boost::metaparse;
  39. using string_literal_parser =
  40. middle_of<
  41. lit_c<'"'>,
  42. repeated<one_char_except<std::integral_constant<char, '"'>>>,
  43. lit_c<'"'>
  44. >;
  45. static_assert(
  46. boost::mpl::equal<
  47. boost::mpl::vector<
  48. boost::mpl::char_<'h'>,
  49. boost::mpl::char_<'e'>,
  50. boost::mpl::char_<'l'>,
  51. boost::mpl::char_<'l'>,
  52. boost::mpl::char_<'o'>
  53. >,
  54. get_result<
  55. string_literal_parser::apply<BOOST_METAPARSE_STRING("\"hello\""), start>
  56. >::type
  57. >::type::value,
  58. "it should return the content of the string literal"
  59. );
  60. [endsect]