1 ///////////////////////////////////////////////////////////////////////////////
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)
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_MATCHER_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_MATCHER_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/mpl/bool.hpp>
17 #include <boost/xpressive/detail/detail_fwd.hpp>
18 #include <boost/xpressive/detail/core/quant_style.hpp>
19 #include <boost/xpressive/detail/core/state.hpp>
21 namespace boost { namespace xpressive { namespace detail
24 ///////////////////////////////////////////////////////////////////////////////
26 // Xpr can be either a static_xpression, or a shared_matchable
27 template<typename Xpr>
29 : quant_style<quant_variable_width, unknown_width::value, Xpr::pure>
31 keeper_matcher(Xpr const &xpr, bool pure = Xpr::pure)
37 template<typename BidiIter, typename Next>
38 bool match(match_state<BidiIter> &state, Next const &next) const
40 return Xpr::pure || this->pure_
41 ? this->match_(state, next, mpl::true_())
42 : this->match_(state, next, mpl::false_());
45 template<typename BidiIter, typename Next>
46 bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const
48 BidiIter const tmp = state.cur_;
50 // matching xpr is guaranteed to not produce side-effects, don't bother saving state
51 if(!this->xpr_.match(state))
55 else if(next.match(state))
64 template<typename BidiIter, typename Next>
65 bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const
67 BidiIter const tmp = state.cur_;
69 // matching xpr could produce side-effects, save state
70 memento<BidiIter> mem = save_sub_matches(state);
72 if(!this->xpr_.match(state))
74 restore_action_queue(mem, state);
75 reclaim_sub_matches(mem, state, false);
78 restore_action_queue(mem, state);
81 reclaim_sub_matches(mem, state, true);
85 restore_sub_matches(mem, state);
91 bool pure_; // false if matching xpr_ could modify the sub-matches