range_c.qbk 1.4 KB

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