repeated1.qbk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. [#repeated1]
  2. [section repeated1]
  3. [h1 Synopsis]
  4. template <class P>
  5. struct repeated1;
  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. It applies `P` on the input string repeatedly as long as the parser accepts the
  13. input. The result of parsing is a sequence of the results of the individual
  14. applications of `P`.
  15. When `P` rejects the input for the first time, `repeated1` rejects it as well.
  16. At least one successful application of `P` is required for `repeated1` to accept
  17. the input.
  18. [h1 Header]
  19. #include <boost/metaparse/repeated1.hpp>
  20. [h1 Expression semantics]
  21. For any `p` parser the following are equivalent:
  22. repeated1<p>
  23. last_of<look_ahead<p>, repeated<p>>
  24. [h1 Example]
  25. #include <boost/metaparse/repeated1.hpp>
  26. #include <boost/metaparse/digit_val.hpp>
  27. #include <boost/metaparse/start.hpp>
  28. #include <boost/metaparse/string.hpp>
  29. #include <boost/metaparse/get_result.hpp>
  30. #include <boost/metaparse/is_error.hpp>
  31. #include <boost/mpl/equal.hpp>
  32. #include <boost/mpl/vector.hpp>
  33. #include <boost/mpl/int.hpp>
  34. using namespace boost::metaparse;
  35. using digits = repeated1<digit_val>;
  36. static_assert(
  37. boost::mpl::equal<
  38. get_result<digits::apply<BOOST_METAPARSE_STRING("1234"), start>>::type,
  39. boost::mpl::vector<
  40. boost::mpl::int_<1>,
  41. boost::mpl::int_<2>,
  42. boost::mpl::int_<3>,
  43. boost::mpl::int_<4>
  44. >
  45. >::type::value,
  46. "the result of parsing should be the list of digit values"
  47. );
  48. static_assert(
  49. is_error<digits::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  50. "repeated1 should reject the input when it can't parse anything with digit_val"
  51. );
  52. [endsect]