digit.qbk 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [#digit]
  2. [section digit]
  3. [h1 Synopsis]
  4. struct digit;
  5. This is a [link parser parser].
  6. [h1 Description]
  7. Parser accepting one character in the range `0-9`. The
  8. result of the parser is the accepted character.
  9. [h1 Header]
  10. #include <boost/metaparse/digit.hpp>
  11. [h1 Expression semantics]
  12. The following are equivalent:
  13. digit
  14. accept_when<one_char, util::is_digit, error::digit_expected>
  15. [h1 Example]
  16. #include <boost/metaparse/digit.hpp>
  17. #include <boost/metaparse/start.hpp>
  18. #include <boost/metaparse/string.hpp>
  19. #include <boost/metaparse/is_error.hpp>
  20. #include <boost/metaparse/get_result.hpp>
  21. using namespace boost::metaparse;
  22. static_assert(
  23. !is_error<digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
  24. "digit should accept a digit"
  25. );
  26. static_assert(
  27. is_error<digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  28. "digit should reject a character"
  29. );
  30. static_assert(
  31. get_result<
  32. digit::apply<BOOST_METAPARSE_STRING("0"), start>
  33. >::type::value == '0',
  34. "the result of parsing should be the character value"
  35. );
  36. [endsect]