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_FLOW_CONTROL_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_FLOW_CONTROL_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/xpressive/detail/detail_fwd.hpp>
17 #include <boost/xpressive/detail/core/regex_impl.hpp>
18 #include <boost/xpressive/detail/core/state.hpp>
19 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
21 namespace boost { namespace xpressive { namespace detail
24 ///////////////////////////////////////////////////////////////////////////////
27 template<typename BidiIter>
28 inline bool push_context_match
30 regex_impl<BidiIter> const &impl
31 , match_state<BidiIter> &state
32 , matchable<BidiIter> const &next
35 // avoid infinite recursion
36 // BUGBUG this only catches direct infinite recursion, like sregex::compile("(?R)"), but
37 // not indirect infinite recursion where two rules invoke each other recursively.
38 if(state.is_active_regex(impl) && state.cur_ == state.sub_match(0).begin_)
40 return next.match(state);
44 match_context<BidiIter> context = state.push_context(impl, next, context);
45 detail::ignore_unused(context);
47 // match the nested regex and uninitialize the match context
48 // (reclaims the sub_match objects if necessary)
49 return state.pop_context(impl, impl.xpr_->match(state));
52 ///////////////////////////////////////////////////////////////////////////////
55 template<typename BidiIter>
56 inline bool pop_context_match(match_state<BidiIter> &state)
59 // BUGBUG nested regex could have changed state.traits_
60 match_context<BidiIter> &context(*state.context_.prev_context_);
61 state.swap_context(context);
63 // Finished matching the nested regex; now match the rest of the enclosing regex
64 bool success = context.next_ptr_->match(state);
67 state.swap_context(context);
71 }}} // namespace boost::xpressive::detail