repeat_begin_matcher.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // repeat_end_matcher.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_BEGIN_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_BEGIN_MATCHER_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/xpressive/detail/detail_fwd.hpp>
  14. #include <boost/xpressive/detail/core/quant_style.hpp>
  15. #include <boost/xpressive/detail/core/state.hpp>
  16. namespace boost { namespace xpressive { namespace detail
  17. {
  18. //
  19. // Note: here is the variable-width xpression quantifier. It always
  20. // matches at least once, so if the min is 0, it is the responsibility
  21. // of the parser to make it alternate with an epsilon matcher.
  22. //
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // repeat_begin_matcher
  25. //
  26. struct repeat_begin_matcher
  27. : quant_style<quant_variable_width, unknown_width::value, false>
  28. {
  29. int mark_number_;
  30. repeat_begin_matcher(int mark_number)
  31. : mark_number_(mark_number)
  32. {
  33. }
  34. template<typename BidiIter, typename Next>
  35. bool match(match_state<BidiIter> &state, Next const &next) const
  36. {
  37. sub_match_impl<BidiIter> &br = state.sub_match(this->mark_number_);
  38. unsigned int old_repeat_count = br.repeat_count_;
  39. bool old_zero_width = br.zero_width_;
  40. br.repeat_count_ = 1;
  41. br.zero_width_ = false;
  42. // "push" next onto the stack, so it can be "popped" in
  43. // repeat_end_matcher and used to loop back.
  44. if(next.BOOST_NESTED_TEMPLATE push_match<Next>(state))
  45. {
  46. return true;
  47. }
  48. br.repeat_count_ = old_repeat_count;
  49. br.zero_width_ = old_zero_width;
  50. return false;
  51. }
  52. };
  53. }}}
  54. #endif