parameterized.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2009 Francois Barel
  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_PARAMETERIZED_AUGUST_09_2009_0539AM)
  8. #define BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/ref.hpp>
  13. #include <boost/spirit/home/support/handles_container.hpp>
  14. #include <boost/spirit/home/qi/parser.hpp>
  15. namespace boost { namespace spirit { namespace qi
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. // parameterized_nonterminal: parser representing the invocation of a
  19. // nonterminal, passing inherited attributes
  20. ///////////////////////////////////////////////////////////////////////////
  21. template <typename Subject, typename Params>
  22. struct parameterized_nonterminal
  23. : parser<parameterized_nonterminal<Subject, Params> >
  24. {
  25. parameterized_nonterminal(Subject const& subject, Params const& params_)
  26. : ref(subject), params(params_)
  27. {
  28. }
  29. template <typename Context, typename Iterator>
  30. struct attribute
  31. // Forward to subject.
  32. : Subject::template attribute<Context, Iterator> {};
  33. template <typename Iterator, typename Context
  34. , typename Skipper, typename Attribute>
  35. bool parse(Iterator& first, Iterator const& last
  36. , Context& context, Skipper const& skipper
  37. , Attribute& attr_) const
  38. {
  39. // Forward to subject, passing the additional
  40. // params argument to parse.
  41. return ref.get().parse(first, last, context, skipper, attr_, params);
  42. }
  43. template <typename Context>
  44. info what(Context& context) const
  45. {
  46. // Forward to subject.
  47. return ref.get().what(context);
  48. }
  49. boost::reference_wrapper<Subject const> ref;
  50. Params params;
  51. };
  52. }}}
  53. namespace boost { namespace spirit { namespace traits
  54. {
  55. ///////////////////////////////////////////////////////////////////////////
  56. template <typename Subject, typename Params, typename Attribute
  57. , typename Context, typename Iterator>
  58. struct handles_container<qi::parameterized_nonterminal<Subject, Params>
  59. , Attribute, Context, Iterator>
  60. : handles_container<typename remove_const<Subject>::type
  61. , Attribute, Context, Iterator>
  62. {};
  63. }}}
  64. #endif