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