repeated_one_of.qbk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. [#repeated_one_of]
  2. [section repeated_one_of]
  3. [h1 Synopsis]
  4. template <class... Ps>
  5. struct repeated_one_of1;
  6. [table Arguments
  7. [[Name] [Type]]
  8. [[`Ps`] [[link parser parser]s]]
  9. ]
  10. This is a [link parser_combinator parser combinator].
  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_of` accepts the input and the result of parsing is an empty
  20. sequence.
  21. On compilers, which are not C++11-compliant, the maximum number of accepted
  22. parsers is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE` macro. Its default
  23. value is 20.
  24. [h1 Header]
  25. #include <boost/metaparse/repeated_one_of.hpp>
  26. [h1 Expression semantics]
  27. For any `p1`, ..., `pn` parsers
  28. repeated_one_of<p1, /* ... */, pn>
  29. is equivalent to
  30. repeated<one_of<p1, /* ... */, pn>>
  31. [h1 Example]
  32. #include <boost/metaparse/repeated_one_of.hpp>
  33. #include <boost/metaparse/lit_c.hpp>
  34. #include <boost/metaparse/start.hpp>
  35. #include <boost/metaparse/string.hpp>
  36. #include <boost/metaparse/get_result.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_of<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. boost::mpl::equal<
  57. get_result<as_and_bs::apply<BOOST_METAPARSE_STRING("x"), start>>::type,
  58. boost::mpl::vector<>
  59. >::type::value,
  60. "repeated_one_of should accept the input when it"
  61. " can't parse anything with digit_val"
  62. );
  63. [endsect]