proxy.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_X3_PROXY_FEBRUARY_1_2013_0211PM)
  7. #define BOOST_SPIRIT_X3_PROXY_FEBRUARY_1_2013_0211PM
  8. #include <boost/spirit/home/x3/core/parser.hpp>
  9. #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
  10. #include <boost/spirit/home/x3/support/traits/attribute_category.hpp>
  11. namespace boost { namespace spirit { namespace x3
  12. {
  13. template <typename Subject, typename Derived>
  14. struct proxy : unary_parser<Subject, Derived>
  15. {
  16. static bool const is_pass_through_unary = true;
  17. proxy(Subject const& subject)
  18. : unary_parser<Subject, Derived>(subject) {}
  19. // Overload this when appropriate. The proxy parser will pick up
  20. // the most derived overload.
  21. template <typename Iterator, typename Context
  22. , typename RuleContext, typename Attribute, typename Category>
  23. bool parse_subject(Iterator& first, Iterator const& last
  24. , Context const& context, RuleContext& rcontext, Attribute& attr, Category) const
  25. {
  26. this->subject.parse(first, last, context, rcontext, attr);
  27. return true;
  28. }
  29. // Main entry point.
  30. template <typename Iterator, typename Context
  31. , typename RuleContext, typename Attribute>
  32. bool parse(Iterator& first, Iterator const& last
  33. , Context const& context, RuleContext& rcontext, Attribute& attr) const
  34. {
  35. return this->derived().parse_subject(first, last, context, rcontext, attr
  36. , typename traits::attribute_category<Attribute>::type());
  37. }
  38. };
  39. }}}
  40. #endif