Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

entire_input

Synopsis

template <class P, class Msg = error::end_of_input_expected>
struct entire_input;

This is a parser combinator.

Table 15. Arguments

Name

Type

P

parser

Msg

parsing error message


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.

Header

#include <boost/metaparse/entire_input.hpp>

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>
>

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"
);

PrevUpHomeNext