plus.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_PLUS_MARCH_13_2007_0127PM)
  8. #define BOOST_SPIRIT_X3_PLUS_MARCH_13_2007_0127PM
  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 plus : unary_parser<Subject, plus<Subject>>
  17. {
  18. typedef unary_parser<Subject, plus<Subject>> base_type;
  19. static bool const handles_container = true;
  20. plus(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. if (!detail::parse_into_container(
  28. this->subject, first, last, context, rcontext, attr))
  29. return false;
  30. while (detail::parse_into_container(
  31. this->subject, first, last, context, rcontext, attr))
  32. ;
  33. return true;
  34. }
  35. };
  36. template <typename Subject>
  37. inline plus<typename extension::as_parser<Subject>::value_type>
  38. operator+(Subject const& subject)
  39. {
  40. return { as_parser(subject) };
  41. }
  42. }}}
  43. namespace boost { namespace spirit { namespace x3 { namespace traits
  44. {
  45. template <typename Subject, typename Context>
  46. struct attribute_of<x3::plus<Subject>, Context>
  47. : build_container<
  48. typename attribute_of<Subject, Context>::type> {};
  49. }}}}
  50. #endif