1 /*============================================================================= 2 Copyright (c) 2003 Joel de Guzman 3 Copyright (c) 2003 Vaclav Vesely 4 http://spirit.sourceforge.net/ 5 6 Distributed under the Boost Software License, Version 1.0. (See accompanying 7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 =============================================================================*/ 9 #ifndef BOOST_SPIRIT_LAZY_HPP 10 #define BOOST_SPIRIT_LAZY_HPP 11 12 //////////////////////////////////////////////////////////////////////////////// 13 #include <boost/spirit/home/classic/namespace.hpp> 14 #include <boost/spirit/home/classic/core/parser.hpp> 15 #include <boost/spirit/home/classic/phoenix/actor.hpp> 16 17 //////////////////////////////////////////////////////////////////////////////// 18 19 namespace boost { namespace spirit { 20 21 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN 22 23 //////////////////////////////////////////////////////////////////////////// 24 // 25 // lazy_parser, holds phoenix actor which returns a spirit parser. 26 // 27 //////////////////////////////////////////////////////////////////////////// 28 29 template<class ActorT> 30 struct lazy_parser : parser<lazy_parser<ActorT> > 31 { 32 typedef lazy_parser<ActorT> self_t; 33 typedef typename ::phoenix::actor_result< 34 ActorT, ::phoenix::tuple<> >::plain_type actor_result_t; 35 36 template<typename ScannerT> 37 struct result 38 { 39 typedef typename 40 parser_result<actor_result_t, ScannerT>::type 41 type; 42 }; 43 lazy_parserboost::spirit::lazy_parser44 lazy_parser(ActorT const& actor_) 45 : actor(actor_) {} 46 47 template<typename ScannerT> 48 typename parser_result<self_t, ScannerT>::type parseboost::spirit::lazy_parser49 parse(ScannerT const& scan) const 50 { return actor().parse(scan); } 51 52 ActorT actor; 53 }; 54 55 ////////////////////////////// 56 // lazy_p, returns lazy_parser 57 // Usage: lazy_p(actor) 58 template<class ActorT> lazy_p(ActorT const & actor)59 lazy_parser<ActorT> lazy_p(ActorT const& actor) 60 { return lazy_parser<ActorT>(actor); } 61 62 BOOST_SPIRIT_CLASSIC_NAMESPACE_END 63 64 }} // namespace BOOST_SPIRIT_CLASSIC_NS 65 66 #endif // BOOST_SPIRIT_LAZY_HPP 67