• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#entire_input]
2[section entire_input]
3
4[h1 Synopsis]
5
6  template <class P, class Msg = error::end_of_input_expected>
7  struct entire_input;
8
9This is a [link parser_combinator parser combinator].
10
11[table Arguments
12  [[Name]  [Type]]
13  [[`P`]   [[link parser parser]]]
14  [[`Msg`] [[link parsing_error_message parsing error message]]]
15]
16
17[h1 Description]
18
19It parses the input using `P` and checks if it consumes the entire input. If `P`
20fails or doesn't consume the entire input, `entire_input` fails. Otherwise
21`entire_input` returns the result of `P`. When `P` does not consume the entire
22input, the error message returned by `entire_input` is `Msg`.
23
24[h1 Header]
25
26  #include <boost/metaparse/entire_input.hpp>
27
28[h1 Expression semantics]
29
30For any `p` parser and `e` parsing error message the following are equivalent
31
32  entire_input<p, e>
33
34  first_of<
35    p,
36    change_error_message<empty</* some metaprogramming value */>, e>
37  >
38
39[h1 Example]
40
41  #include <boost/metaparse/entire_input.hpp>
42  #include <boost/metaparse/int_.hpp>
43  #include <boost/metaparse/string.hpp>
44  #include <boost/metaparse/start.hpp>
45  #include <boost/metaparse/get_result.hpp>
46  #include <boost/metaparse/get_message.hpp>
47  #include <boost/metaparse/define_error.hpp>
48
49  using namespace boost::metaparse;
50
51  BOOST_METAPARSE_DEFINE_ERROR(extra_chars_at_end, "Extra chars at end");
52
53  using int_parser = entire_input<int_, extra_chars_at_end>;
54
55  static_assert(
56    get_result<
57      int_parser::apply<BOOST_METAPARSE_STRING("1113"), start>
58    >::type::value == 1113,
59    "it should parse the input if it contains only an integer"
60  );
61
62  static_assert(
63    std::is_same<
64      get_message<
65        int_parser::apply<BOOST_METAPARSE_STRING("1113mm"), start>
66      >::type,
67      extra_chars_at_end
68    >::type::value,
69    "it should return the specified error message when there are extra characters"
70  );
71
72[endsect]
73
74