74 lines
1.9 KiB
Plaintext
74 lines
1.9 KiB
Plaintext
[#entire_input]
|
|
[section entire_input]
|
|
|
|
[h1 Synopsis]
|
|
|
|
template <class P, class Msg = error::end_of_input_expected>
|
|
struct entire_input;
|
|
|
|
This is a [link parser_combinator parser combinator].
|
|
|
|
[table Arguments
|
|
[[Name] [Type]]
|
|
[[`P`] [[link parser parser]]]
|
|
[[`Msg`] [[link parsing_error_message parsing error message]]]
|
|
]
|
|
|
|
[h1 Description]
|
|
|
|
It parses the input using `P` and checks if it consumes the entire input. If `P`
|
|
fails or doesn't consume the entire input, `entire_input` fails. Otherwise
|
|
`entire_input` returns the result of `P`. When `P` does not consume the entire
|
|
input, the error message returned by `entire_input` is `Msg`.
|
|
|
|
[h1 Header]
|
|
|
|
#include <boost/metaparse/entire_input.hpp>
|
|
|
|
[h1 Expression semantics]
|
|
|
|
For any `p` parser and `e` parsing error message the following are equivalent
|
|
|
|
entire_input<p, e>
|
|
|
|
first_of<
|
|
p,
|
|
change_error_message<empty</* some metaprogramming value */>, e>
|
|
>
|
|
|
|
[h1 Example]
|
|
|
|
#include <boost/metaparse/entire_input.hpp>
|
|
#include <boost/metaparse/int_.hpp>
|
|
#include <boost/metaparse/string.hpp>
|
|
#include <boost/metaparse/start.hpp>
|
|
#include <boost/metaparse/get_result.hpp>
|
|
#include <boost/metaparse/get_message.hpp>
|
|
#include <boost/metaparse/define_error.hpp>
|
|
|
|
using namespace boost::metaparse;
|
|
|
|
BOOST_METAPARSE_DEFINE_ERROR(extra_chars_at_end, "Extra chars at end");
|
|
|
|
using int_parser = entire_input<int_, extra_chars_at_end>;
|
|
|
|
static_assert(
|
|
get_result<
|
|
int_parser::apply<BOOST_METAPARSE_STRING("1113"), start>
|
|
>::type::value == 1113,
|
|
"it should parse the input if it contains only an integer"
|
|
);
|
|
|
|
static_assert(
|
|
std::is_same<
|
|
get_message<
|
|
int_parser::apply<BOOST_METAPARSE_STRING("1113mm"), start>
|
|
>::type,
|
|
extra_chars_at_end
|
|
>::type::value,
|
|
"it should return the specified error message when there are extra characters"
|
|
);
|
|
|
|
[endsect]
|
|
|