repeated_reject_incomplete.qbk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. [#repeated_reject_incomplete]
  2. [section repeated_reject_incomplete]
  3. [h1 Synopsis]
  4. template <class P>
  5. struct repeated_reject_incomplete;
  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 repeated `repeated`], but once `P` rejects the input,
  13. `repeated_reject_incomplete` checks if `P` consumes any characters before
  14. rejecting the input. If so, `repeated_reject_incomplete` rejects the input with
  15. the same error message this last application of `P` returned. Otherwise
  16. `repeated_reject_incomplete` accepts the input and gives the same result as
  17. [link repeated `repeated`].
  18. Here is a diagram showing how `repeated_reject_incomplete` works by example:
  19. using int_token = token<int_>;
  20. using plus_token = token<lit_c<'+'>>;
  21. using plus_int = last_of<plus_token, int_token>;
  22. using sum_op = mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type;
  23. [$images/metaparse/repeated_reject_incomplete_diag1.png [width 70%]]
  24. [h1 Header]
  25. #include <boost/metaparse/repeated_reject_incomplete.hpp>
  26. [h1 Expression semantics]
  27. For any `p` parser, `s` compile-time string and `pos` source position
  28. repeated_reject_incomplete<p>::apply<s, pos>
  29. is equivalent to
  30. first_of<repeated<p>, fail_at_first_char_expected<p> >::apply<s, pos>
  31. [h1 Example]
  32. #include <boost/metaparse/repeated_reject_incomplete.hpp>
  33. #include <boost/metaparse/lit_c.hpp>
  34. #include <boost/metaparse/last_of.hpp>
  35. #include <boost/metaparse/token.hpp>
  36. #include <boost/metaparse/int_.hpp>
  37. #include <boost/metaparse/string.hpp>
  38. #include <boost/metaparse/start.hpp>
  39. #include <boost/metaparse/get_result.hpp>
  40. #include <boost/metaparse/is_error.hpp>
  41. #include <boost/mpl/equal.hpp>
  42. #include <boost/mpl/vector_c.hpp>
  43. using namespace boost::metaparse;
  44. using int_token = token<int_>;
  45. using plus_token = token<lit_c<'+'>>;
  46. using plus_int = last_of<plus_token, int_token>;
  47. using ints = repeated_reject_incomplete<plus_int>;
  48. static_assert(
  49. boost::mpl::equal<
  50. boost::mpl::vector_c<int, 13, 3, 21>,
  51. get_result<
  52. ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 + 21"), start>
  53. >::type
  54. >::type::value,
  55. "ints should parse the numbers"
  56. );
  57. static_assert(
  58. is_error<
  59. ints::apply<BOOST_METAPARSE_STRING("+ 13 + 3 +"), start>
  60. >::type::value,
  61. "when the last number is missing, it should be an error"
  62. );
  63. [endsect]