repeated_one_of1.qbk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [#repeated_one_of1]
  2. [section repeated_one_of1]
  3. [h1 Synopsis]
  4. template <class... Ps>
  5. struct repeated_one_of1;
  6. This is a [link parser_combinator parser combinator].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Ps`] [[link parser parser]s]]
  10. ]
  11. [h1 Description]
  12. It applies the `Ps...` parsers repeatedly as long as any of them accepts the
  13. input. In each iteration the parsers are tried in order and the first one
  14. accepting the input is used, therefore in case of ambiguous grammars the result
  15. of parsing depends on the order of the `Ps...` parsers. The result of parsing
  16. with this [link parser_combinator parser combinator] is a sequence of the
  17. individual parsing results.
  18. When none of the `Ps...` parsers accept the input in the first iteration,
  19. `repeated_one_of1` rejects the input.
  20. On compilers, which are not C++11-compliant, the maximum number of accepted
  21. parsers is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE` macro. Its default
  22. value is 20.
  23. [h1 Header]
  24. #include <boost/metaparse/repeated_one_of1.hpp>
  25. [h1 Expression semantics]
  26. For any `p1`, ..., `pn` parsers
  27. repeated_one_of1<p1, /* ... */, pn>
  28. is equivalent to
  29. repeated1<one_of<p1, /* ... */, pn>>
  30. [h1 Example]
  31. #include <boost/metaparse/repeated_one_of1.hpp>
  32. #include <boost/metaparse/lit_c.hpp>
  33. #include <boost/metaparse/start.hpp>
  34. #include <boost/metaparse/string.hpp>
  35. #include <boost/metaparse/get_result.hpp>
  36. #include <boost/metaparse/is_error.hpp>
  37. #include <boost/mpl/equal.hpp>
  38. #include <boost/mpl/vector.hpp>
  39. #include <boost/mpl/char.hpp>
  40. using namespace boost::metaparse;
  41. using as_and_bs = repeated_one_of1<lit_c<'a'>, lit_c<'b'>>;
  42. static_assert(
  43. boost::mpl::equal<
  44. get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("abaab"), start>>::type,
  45. boost::mpl::vector<
  46. boost::mpl::char_<'a'>,
  47. boost::mpl::char_<'b'>,
  48. boost::mpl::char_<'a'>,
  49. boost::mpl::char_<'a'>,
  50. boost::mpl::char_<'b'>
  51. >
  52. >::type::value,
  53. "the result of parsing should be the list of results"
  54. );
  55. static_assert(
  56. is_error<as_and_bs::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  57. "repeated_one_of1 should reject the input when it"
  58. " can't parse anything with digit_val"
  59. );
  60. [endsect]