File indexing completed on 2025-01-18 09:53:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_END_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_END_MATCHER_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <boost/mpl/bool.hpp>
0017 #include <boost/xpressive/detail/detail_fwd.hpp>
0018 #include <boost/xpressive/detail/core/quant_style.hpp>
0019 #include <boost/xpressive/detail/core/state.hpp>
0020
0021 namespace boost { namespace xpressive { namespace detail
0022 {
0023
0024
0025
0026
0027 template<typename Greedy>
0028 struct repeat_end_matcher
0029 : quant_style<quant_none, 0, false>
0030 {
0031 typedef Greedy greedy_type;
0032 int mark_number_;
0033 unsigned int min_, max_;
0034 mutable void const *back_;
0035
0036 repeat_end_matcher(int mark_nbr, unsigned int min, unsigned int max)
0037 : mark_number_(mark_nbr)
0038 , min_(min)
0039 , max_(max)
0040 , back_(0)
0041 {
0042 }
0043
0044 template<typename BidiIter, typename Next>
0045 bool match(match_state<BidiIter> &state, Next const &next) const
0046 {
0047
0048 sub_match_impl<BidiIter> &br = state.sub_match(this->mark_number_);
0049
0050 if(br.zero_width_ && br.begin_ == state.cur_)
0051 {
0052 return next.skip_match(state);
0053 }
0054
0055 bool old_zero_width = br.zero_width_;
0056 br.zero_width_ = (br.begin_ == state.cur_);
0057
0058 if(this->match_(state, next, greedy_type()))
0059 {
0060 return true;
0061 }
0062
0063 br.zero_width_ = old_zero_width;
0064 return false;
0065 }
0066
0067
0068 template<typename BidiIter, typename Next>
0069 bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const
0070 {
0071 sub_match_impl<BidiIter> &br = state.sub_match(this->mark_number_);
0072
0073 if(this->max_ > br.repeat_count_)
0074 {
0075 ++br.repeat_count_;
0076
0077 if(next.top_match(state, this->back_))
0078 {
0079 return true;
0080 }
0081 else if(--br.repeat_count_ < this->min_)
0082 {
0083 return false;
0084 }
0085 }
0086
0087
0088 return next.skip_match(state);
0089 }
0090
0091
0092 template<typename BidiIter, typename Next>
0093 bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const
0094 {
0095 sub_match_impl<BidiIter> &br = state.sub_match(this->mark_number_);
0096
0097 if(this->min_ <= br.repeat_count_)
0098 {
0099 if(next.skip_match(state))
0100 {
0101 return true;
0102 }
0103 }
0104
0105 if(this->max_ > br.repeat_count_)
0106 {
0107 ++br.repeat_count_;
0108 if(next.top_match(state, this->back_))
0109 {
0110 return true;
0111 }
0112 --br.repeat_count_;
0113 }
0114
0115 return false;
0116 }
0117 };
0118
0119 }}}
0120
0121 #endif