plus.hpp 2.3 KB

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