lazy.hpp 2.1 KB

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