entire_input.qbk 1.9 KB

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