repeated_reject_incomplete1.qbk 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. [#repeated_reject_incomplete1]
  2. [section repeated_reject_incomplete1]
  3. [h1 Synopsis]
  4. template <class P>
  5. struct repeated_reject_incomplete1;
  6. This is a [link parser_combinator parser combinator].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`P`] [[link parser parser]]]
  10. ]
  11. [h1 Description]
  12. The same as [link repeated1 `repeated1`], but once `P` rejects the input,
  13. `repeated_reject_incomplete1` checks if `P` consumes any characters before
  14. rejecting the input. If so, `repeated_reject_incomplete1` rejects the input with
  15. the same error message this last application of `P` returned. Otherwise
  16. _reject_incomplete`repeated1` accepts the input and gives the same result as
  17. [link repeated1 `repeated1`].
  18. [h1 Header]
  19. #include <boost/metaparse/repeated_reject_incomplete1.hpp>
  20. [h1 Expression semantics]
  21. For any `p` parser, `s` compile-time string and `pos` source position
  22. repeated_reject_incomplete1<p>::apply<s, pos>
  23. is equivalent to
  24. first_of<repeated1<p>, fail_at_first_char_expected<p> >::apply<s, pos>
  25. [h1 Example]
  26. #include <boost/metaparse/repeated_reject_incomplete1.hpp>
  27. #include <boost/metaparse/lit_c.hpp>
  28. #include <boost/metaparse/last_of.hpp>
  29. #include <boost/metaparse/token.hpp>
  30. #include <boost/metaparse/int_.hpp>
  31. #include <boost/metaparse/string.hpp>
  32. #include <boost/metaparse/start.hpp>
  33. #include <boost/metaparse/get_result.hpp>
  34. #include <boost/metaparse/is_error.hpp>
  35. #include <boost/mpl/equal.hpp>
  36. #include <boost/mpl/vector_c.hpp>
  37. using namespace boost::metaparse;
  38. using int_token = token<int_>;
  39. using plus_token = token<lit_c<'+'>>;
  40. using plus_int = last_of<plus_token, int_token>;
  41. using ints = repeated_reject_incomplete1<plus_int>;
  42. static_assert(
  43. boost::mpl::equal<
  44. boost::mpl::vector_c<int, 13, 3, 21>,
  45. get_result<
  46. ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
  47. >::type
  48. >::type::value,
  49. "ints should parse the numbers"
  50. );
  51. static_assert(
  52. is_error<
  53. ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
  54. >::type::value,
  55. "when the last number is missing, it should be an error"
  56. );
  57. static_assert(
  58. is_error<ints::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
  59. "when no numbers are provided, it should be an error"
  60. );
  61. [endsect]