kleene.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_KLEENE_JANUARY_07_2007_0818AM)
  8. #define BOOST_SPIRIT_X3_KLEENE_JANUARY_07_2007_0818AM
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. #include <boost/spirit/home/x3/support/traits/container_traits.hpp>
  11. #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
  12. #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
  13. namespace boost { namespace spirit { namespace x3
  14. {
  15. template <typename Subject>
  16. struct kleene : unary_parser<Subject, kleene<Subject>>
  17. {
  18. typedef unary_parser<Subject, kleene<Subject>> base_type;
  19. static bool const handles_container = true;
  20. kleene(Subject const& subject)
  21. : base_type(subject) {}
  22. template <typename Iterator, typename Context
  23. , typename RContext, typename Attribute>
  24. bool parse(Iterator& first, Iterator const& last
  25. , Context const& context, RContext& rcontext, Attribute& attr) const
  26. {
  27. while (detail::parse_into_container(
  28. this->subject, first, last, context, rcontext, attr))
  29. ;
  30. return true;
  31. }
  32. };
  33. template <typename Subject>
  34. inline kleene<typename extension::as_parser<Subject>::value_type>
  35. operator*(Subject const& subject)
  36. {
  37. return { as_parser(subject) };
  38. }
  39. }}}
  40. namespace boost { namespace spirit { namespace x3 { namespace traits
  41. {
  42. template <typename Subject, typename Context>
  43. struct attribute_of<x3::kleene<Subject>, Context>
  44. : build_container<
  45. typename attribute_of<Subject, Context>::type> {};
  46. }}}}
  47. #endif