flush_multi_pass.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Daniel Nuffer
  3. http://spirit.sourceforge.net/
  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)
  6. =============================================================================*/
  7. #ifndef BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP
  8. #define BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include <boost/spirit/home/classic/namespace.hpp>
  11. #include <boost/spirit/home/classic/core.hpp>
  12. #include <boost/spirit/home/classic/iterator/multi_pass.hpp>
  13. ///////////////////////////////////////////////////////////////////////////////
  14. namespace boost { namespace spirit {
  15. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  16. namespace impl {
  17. template <typename T>
  18. void flush_iterator(T &) {}
  19. template <typename T1, typename T2, typename T3, typename T4>
  20. void flush_iterator(BOOST_SPIRIT_CLASSIC_NS::multi_pass<
  21. T1, T2, T3, T4, BOOST_SPIRIT_CLASSIC_NS::multi_pass_policies::std_deque> &i)
  22. {
  23. i.clear_queue();
  24. }
  25. } // namespace impl
  26. ///////////////////////////////////////////////////////////////////////////
  27. //
  28. // flush_multi_pass_parser
  29. //
  30. // The flush_multi_pass_parser flushes an underlying
  31. // multi_pass_iterator during the normal parsing process. This may
  32. // be used at certain points during the parsing process, when it is
  33. // clear, that no backtracking is needed anymore and the input
  34. // gathered so far may be discarded.
  35. //
  36. ///////////////////////////////////////////////////////////////////////////
  37. class flush_multi_pass_parser
  38. : public parser<flush_multi_pass_parser>
  39. {
  40. public:
  41. typedef flush_multi_pass_parser this_t;
  42. template <typename ScannerT>
  43. typename parser_result<this_t, ScannerT>::type
  44. parse(ScannerT const& scan) const
  45. {
  46. impl::flush_iterator(scan.first);
  47. return scan.empty_match();
  48. }
  49. };
  50. ///////////////////////////////////////////////////////////////////////////
  51. //
  52. // predefined flush_multi_pass_p object
  53. //
  54. // This object should may used to flush a multi_pass_iterator along
  55. // the way during the normal parsing process.
  56. //
  57. ///////////////////////////////////////////////////////////////////////////
  58. flush_multi_pass_parser const
  59. flush_multi_pass_p = flush_multi_pass_parser();
  60. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  61. }} // namespace BOOST_SPIRIT_CLASSIC_NS
  62. #endif // BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP