| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | Copyright (c) 2009 Francois Barel |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | ==============================================================================*/ |
| 8 | #if !defined(BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM) |
| 9 | #define BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM |
| 10 | |
| 11 | #if defined(_MSC_VER) |
| 12 | #pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <boost/ref.hpp> |
| 16 | |
| 17 | #include <boost/spirit/home/support/handles_container.hpp> |
| 18 | #include <boost/spirit/home/qi/parser.hpp> |
| 19 | |
| 20 | namespace boost { namespace spirit { namespace qi |
| 21 | { |
| 22 | /////////////////////////////////////////////////////////////////////////// |
| 23 | // parameterized_nonterminal: parser representing the invocation of a |
| 24 | // nonterminal, passing inherited attributes |
| 25 | /////////////////////////////////////////////////////////////////////////// |
| 26 | template <typename Subject, typename Params> |
| 27 | struct parameterized_nonterminal |
| 28 | : parser<parameterized_nonterminal<Subject, Params> > |
| 29 | { |
| 30 | parameterized_nonterminal(Subject const& subject, Params const& params_) |
| 31 | : ref(subject), params(params_) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | template <typename Context, typename Iterator> |
| 36 | struct attribute |
| 37 | // Forward to subject. |
| 38 | : Subject::template attribute<Context, Iterator> {}; |
| 39 | |
| 40 | template <typename Iterator, typename Context |
| 41 | , typename Skipper, typename Attribute> |
| 42 | bool parse(Iterator& first, Iterator const& last |
| 43 | , Context& context, Skipper const& skipper |
| 44 | , Attribute& attr_) const |
| 45 | { |
| 46 | // Forward to subject, passing the additional |
| 47 | // params argument to parse. |
| 48 | return ref.get().parse(first, last, context, skipper, attr_, params); |
| 49 | } |
| 50 | |
| 51 | template <typename Context> |
| 52 | info what(Context& context) const |
| 53 | { |
| 54 | // Forward to subject. |
| 55 | return ref.get().what(context); |
| 56 | } |
| 57 | |
| 58 | boost::reference_wrapper<Subject const> ref; |
| 59 | Params params; |
| 60 | }; |
| 61 | }}} |
| 62 | |
| 63 | namespace boost { namespace spirit { namespace traits |
| 64 | { |
| 65 | /////////////////////////////////////////////////////////////////////////// |
| 66 | template <typename Subject, typename Params, typename Attribute |
| 67 | , typename Context, typename Iterator> |
| 68 | struct handles_container<qi::parameterized_nonterminal<Subject, Params> |
| 69 | , Attribute, Context, Iterator> |
| 70 | : handles_container<typename remove_const<Subject>::type |
| 71 | , Attribute, Context, Iterator> |
| 72 | {}; |
| 73 | }}} |
| 74 | |
| 75 | #endif |
| 76 | |