File indexing completed on 2025-01-18 09:53:48
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_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 Xpr>
0028 struct keeper_matcher
0029 : quant_style<quant_variable_width, unknown_width::value, Xpr::pure>
0030 {
0031 keeper_matcher(Xpr const &xpr, bool pure = Xpr::pure)
0032 : xpr_(xpr)
0033 , pure_(pure)
0034 {
0035 }
0036
0037 template<typename BidiIter, typename Next>
0038 bool match(match_state<BidiIter> &state, Next const &next) const
0039 {
0040 return Xpr::pure || this->pure_
0041 ? this->match_(state, next, mpl::true_())
0042 : this->match_(state, next, mpl::false_());
0043 }
0044
0045 template<typename BidiIter, typename Next>
0046 bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const
0047 {
0048 BidiIter const tmp = state.cur_;
0049
0050
0051 if(!this->xpr_.match(state))
0052 {
0053 return false;
0054 }
0055 else if(next.match(state))
0056 {
0057 return true;
0058 }
0059
0060 state.cur_ = tmp;
0061 return false;
0062 }
0063
0064 template<typename BidiIter, typename Next>
0065 bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const
0066 {
0067 BidiIter const tmp = state.cur_;
0068
0069
0070 memento<BidiIter> mem = save_sub_matches(state);
0071
0072 if(!this->xpr_.match(state))
0073 {
0074 restore_action_queue(mem, state);
0075 reclaim_sub_matches(mem, state, false);
0076 return false;
0077 }
0078 restore_action_queue(mem, state);
0079 if(next.match(state))
0080 {
0081 reclaim_sub_matches(mem, state, true);
0082 return true;
0083 }
0084
0085 restore_sub_matches(mem, state);
0086 state.cur_ = tmp;
0087 return false;
0088 }
0089
0090 Xpr xpr_;
0091 bool pure_;
0092 };
0093
0094 }}}
0095
0096 #endif