1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
7 #if !defined(BOOST_SPIRIT_LEX_REFERENCE_APR_20_2009_0827AM)
8 #define BOOST_SPIRIT_LEX_REFERENCE_APR_20_2009_0827AM
14 #include <boost/spirit/home/lex/meta_compiler.hpp>
15 #include <boost/spirit/home/lex/lexer_type.hpp>
16 #include <boost/spirit/home/qi/reference.hpp>
17 #include <boost/spirit/home/support/info.hpp>
18 #include <boost/spirit/home/support/handles_container.hpp>
19 #include <boost/ref.hpp>
21 namespace boost { namespace spirit { namespace lex
23 ///////////////////////////////////////////////////////////////////////////
24 // reference is a lexer that references another lexer (its Subject)
25 // all lexer components are at the same time
26 ///////////////////////////////////////////////////////////////////////////
27 template <typename Subject, typename IdType = unused_type>
30 template <typename Subject>
31 struct reference<Subject, unused_type>
32 : qi::reference<Subject>
33 , lexer_type<reference<Subject> >
35 reference(Subject& subject)
36 : qi::reference<Subject>(subject) {}
38 template <typename LexerDef, typename String>
39 void collect(LexerDef& lexdef, String const& state
40 , String const& targetstate) const
42 this->ref.get().collect(lexdef, state, targetstate);
45 template <typename LexerDef>
46 void add_actions(LexerDef& lexdef) const
48 this->ref.get().add_actions(lexdef);
52 template <typename Subject, typename IdType>
53 struct reference : reference<Subject>
55 reference(Subject& subject)
56 : reference<Subject>(subject) {}
60 return this->ref.get().id();
62 std::size_t unique_id() const
64 return this->ref.get().unique_id();
66 std::size_t state() const
68 return this->ref.get().state();
73 namespace boost { namespace spirit { namespace traits
75 ///////////////////////////////////////////////////////////////////////////
76 template <typename Subject, typename IdType
77 , typename Attribute, typename Context, typename Iterator>
78 struct handles_container<lex::reference<Subject, IdType>
79 , Attribute, Context, Iterator>
81 typename remove_const<Subject>::type, Attribute, Context, Iterator>