sl@0: /*=============================================================================
sl@0:     Copyright (c) 2003 Joel de Guzman
sl@0:     Copyright (c) 2003 Vaclav Vesely
sl@0:     http://spirit.sourceforge.net/
sl@0: 
sl@0:     Use, modification and distribution is subject to the Boost Software
sl@0:     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0:     http://www.boost.org/LICENSE_1_0.txt)
sl@0: =============================================================================*/
sl@0: #ifndef BOOST_SPIRIT_LAZY_HPP
sl@0: #define BOOST_SPIRIT_LAZY_HPP
sl@0: 
sl@0: ////////////////////////////////////////////////////////////////////////////////
sl@0: #include <boost/spirit/core/parser.hpp>
sl@0: #include <boost/spirit/phoenix/actor.hpp>
sl@0: 
sl@0: ////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: namespace boost { namespace spirit
sl@0: {
sl@0:     ////////////////////////////////////////////////////////////////////////////
sl@0:     //
sl@0:     // lazy_parser, holds phoenix actor which returns a spirit parser.
sl@0:     //
sl@0:     ////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0:     template<class ActorT>
sl@0:     struct lazy_parser : parser<lazy_parser<ActorT> >
sl@0:     {
sl@0:         typedef lazy_parser<ActorT> self_t;
sl@0:         typedef typename phoenix::actor_result<
sl@0:             ActorT, phoenix::tuple<> >::plain_type actor_result_t;
sl@0: 
sl@0:         template<typename ScannerT>
sl@0:         struct result
sl@0:         {
sl@0:             typedef typename
sl@0:                 parser_result<actor_result_t, ScannerT>::type
sl@0:             type;
sl@0:         };
sl@0: 
sl@0:         lazy_parser(ActorT const& actor_)
sl@0:         : actor(actor_) {}
sl@0: 
sl@0:         template<typename ScannerT>
sl@0:         typename parser_result<self_t, ScannerT>::type
sl@0:         parse(ScannerT const& scan) const
sl@0:         { return actor().parse(scan); }
sl@0: 
sl@0:         ActorT actor;
sl@0:     };
sl@0: 
sl@0:     //////////////////////////////
sl@0:     // lazy_p, returns lazy_parser
sl@0:     // Usage: lazy_p(actor)
sl@0:     template<class ActorT>
sl@0:     lazy_parser<ActorT> lazy_p(ActorT const& actor)
sl@0:     { return lazy_parser<ActorT>(actor); }
sl@0: 
sl@0: }} // namespace boost::spirit
sl@0: 
sl@0: #endif // BOOST_SPIRIT_LAZY_HPP