1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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_REFERENCE_OCTOBER_31_2008_1218AM)
8 #define BOOST_SPIRIT_REFERENCE_OCTOBER_31_2008_1218AM
14 #include <boost/spirit/home/qi/meta_compiler.hpp>
15 #include <boost/spirit/home/qi/parser.hpp>
16 #include <boost/spirit/home/support/info.hpp>
17 #include <boost/spirit/home/support/handles_container.hpp>
18 #include <boost/type_traits/remove_const.hpp>
19 #include <boost/ref.hpp>
21 namespace boost { namespace spirit { namespace qi
23 ///////////////////////////////////////////////////////////////////////////
24 // reference is a parser that references another parser (its Subject)
25 ///////////////////////////////////////////////////////////////////////////
26 template <typename Subject>
27 struct reference : parser<reference<Subject> >
29 typedef Subject subject_type;
31 reference(Subject& subject)
34 template <typename Context, typename Iterator>
35 struct attribute : Subject::template attribute<Context, Iterator> {};
37 template <typename Iterator, typename Context
38 , typename Skipper, typename Attribute>
39 bool parse(Iterator& first, Iterator const& last
40 , Context& context, Skipper const& skipper
41 , Attribute& attr_) const
43 return ref.get().parse(first, last, context, skipper, attr_);
46 template <typename Context>
47 info what(Context& context) const
49 // the reference is transparent (does not add any info)
50 return ref.get().what(context);
53 boost::reference_wrapper<Subject> ref;
57 namespace boost { namespace spirit { namespace traits
59 ///////////////////////////////////////////////////////////////////////////
60 template <typename Subject, typename Attribute, typename Context
62 struct handles_container<qi::reference<Subject>, Attribute, Context
64 : handles_container<typename remove_const<Subject>::type
65 , Attribute, Context, Iterator>