Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:48

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // optional_matcher.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_OPTIONAL_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_OPTIONAL_MATCHER_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
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     // optional_matcher
0026     template<typename Xpr, typename Greedy>
0027     struct optional_matcher
0028       : quant_style<quant_variable_width, unknown_width::value, Xpr::pure>
0029     {
0030         Xpr xpr_;
0031 
0032         explicit optional_matcher(Xpr const &xpr)
0033           : xpr_(xpr)
0034         {
0035         }
0036 
0037         template<typename BidiIter, typename Next>
0038         bool match(match_state<BidiIter> &state, Next const &next) const
0039         {
0040             return this->match_(state, next, Greedy());
0041         }
0042 
0043     private:
0044         template<typename BidiIter, typename Next>
0045         bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const // Greedy
0046         {
0047             return this->xpr_.BOOST_NESTED_TEMPLATE push_match<Next>(state)
0048                 || next.match(state);
0049         }
0050 
0051         template<typename BidiIter, typename Next>
0052         bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const // Non-greedy
0053         {
0054             return next.match(state)
0055                 || this->xpr_.BOOST_NESTED_TEMPLATE push_match<Next>(state);
0056         }
0057 
0058         optional_matcher &operator =(optional_matcher const &);
0059     };
0060 
0061     ///////////////////////////////////////////////////////////////////////////////
0062     // optional_mark_matcher
0063     template<typename BidiIter, typename Next>
0064     inline bool match_next(match_state<BidiIter> &state, Next const &next, int mark_number)
0065     {
0066         sub_match_impl<BidiIter> &br = state.sub_match(mark_number);
0067 
0068         bool old_matched = br.matched;
0069         br.matched = false;
0070 
0071         if(next.match(state))
0072         {
0073             return true;
0074         }
0075 
0076         br.matched = old_matched;
0077         return false;
0078     }
0079 
0080     ///////////////////////////////////////////////////////////////////////////////
0081     // optional_mark_matcher
0082     template<typename Xpr, typename Greedy>
0083     struct optional_mark_matcher
0084       : quant_style<quant_variable_width, unknown_width::value, Xpr::pure>
0085     {
0086         Xpr xpr_;
0087         int mark_number_;
0088 
0089         explicit optional_mark_matcher(Xpr const &xpr, int mark_number)
0090           : xpr_(xpr)
0091           , mark_number_(mark_number)
0092         {
0093         }
0094 
0095         template<typename BidiIter, typename Next>
0096         bool match(match_state<BidiIter> &state, Next const &next) const
0097         {
0098             return this->match_(state, next, Greedy());
0099         }
0100 
0101     private:
0102         template<typename BidiIter, typename Next>
0103         bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const // Greedy
0104         {
0105             return this->xpr_.BOOST_NESTED_TEMPLATE push_match<Next>(state)
0106                 || match_next(state, next, this->mark_number_);
0107         }
0108 
0109         template<typename BidiIter, typename Next>
0110         bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const // Non-greedy
0111         {
0112             return match_next(state, next, this->mark_number_)
0113                 || this->xpr_.BOOST_NESTED_TEMPLATE push_match<Next>(state);
0114         }
0115 
0116         optional_mark_matcher &operator =(optional_mark_matcher const &);
0117     };
0118 
0119 }}}
0120 
0121 #endif