metaparse/doc/range.qbk
2015-07-19 09:53:35 +02:00

68 lines
1.5 KiB
Plaintext

[#range]
[section range]
[h1 Synopsis]
template <class From, class To>
struct range;
This is a [link parser parser].
[table Arguments
[[Name] [Type]]
[[`From`] [[link boxed_value boxed] character value]]
[[`To`] [[link boxed_value boxed] character value]]
]
[h1 Description]
`range` accepts one character in the range `[From..To]`. The result of the
parser is the accepted character.
[h1 Header]
#include <boost/metaparse/range.hpp>
[h1 Expression semantics]
For any `A`, `B` wrapped characters the following are equivalent:
range<A, B>
accept_when<one_char, util::in_range<A, B>, errors::unexpected_character>
[h1 Example]
#include <boost/metaparse/range.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_result.hpp>
#include <type_traits>
using namespace boost::metaparse;
using one_digit =
range<std::integral_constant<char, '0'>, std::integral_constant<char, '9'>>;
static_assert(
!is_error<one_digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
"one_digit should accept a digit"
);
static_assert(
is_error<one_digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
"one_digit should reject a value outside of ['0'..'9']"
);
static_assert(
get_result<
one_digit::apply<BOOST_METAPARSE_STRING("0"), start>
>::type::value == '0',
"the result of parsing should be the character value"
);
[endsect]