range.qbk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. [#range]
  2. [section range]
  3. [h1 Synopsis]
  4. template <class From, class To>
  5. struct range;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`From`] [[link boxed_value boxed] character value]]
  10. [[`To`] [[link boxed_value boxed] character value]]
  11. ]
  12. [h1 Description]
  13. `range` accepts one character in the range `[From..To]`. The result of the
  14. parser is the accepted character.
  15. [h1 Header]
  16. #include <boost/metaparse/range.hpp>
  17. [h1 Expression semantics]
  18. For any `A`, `B` wrapped characters the following are equivalent:
  19. range<A, B>
  20. accept_when<one_char, util::in_range<A, B>, errors::unexpected_character>
  21. [h1 Example]
  22. #include <boost/metaparse/range.hpp>
  23. #include <boost/metaparse/start.hpp>
  24. #include <boost/metaparse/string.hpp>
  25. #include <boost/metaparse/is_error.hpp>
  26. #include <boost/metaparse/get_result.hpp>
  27. #include <type_traits>
  28. using namespace boost::metaparse;
  29. using one_digit =
  30. range<std::integral_constant<char, '0'>, std::integral_constant<char, '9'>>;
  31. static_assert(
  32. !is_error<one_digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
  33. "one_digit should accept a digit"
  34. );
  35. static_assert(
  36. is_error<one_digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  37. "one_digit should reject a value outside of ['0'..'9']"
  38. );
  39. static_assert(
  40. get_result<
  41. one_digit::apply<BOOST_METAPARSE_STRING("0"), start>
  42. >::type::value == '0',
  43. "the result of parsing should be the character value"
  44. );
  45. [endsect]