Update of /cvsroot/boost/boost/boost/xpressive/detail/core/matcher
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20098/detail/core/matcher

Modified Files:
        action_matcher.hpp end_matcher.hpp keeper_matcher.hpp 
        lookahead_matcher.hpp lookbehind_matcher.hpp 
Log Message:
experimental xpressive actions

Index: action_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/action_matcher.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- action_matcher.hpp  29 Oct 2006 06:14:41 -0000      1.5
+++ action_matcher.hpp  22 Mar 2007 17:37:16 -0000      1.6
@@ -13,63 +13,138 @@
 # pragma once
 #endif
 
+#include <boost/assert.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
-#include <boost/xpressive/detail/core/access.hpp>
 #include <boost/xpressive/detail/core/quant_style.hpp>
+#include <boost/xpressive/detail/core/action.hpp>
 #include <boost/xpressive/detail/core/state.hpp>
+#include <boost/xpressive/proto/proto.hpp>
+#include <boost/xpressive/proto/context.hpp>
 
 namespace boost { namespace xpressive { namespace detail
 {
 
     
///////////////////////////////////////////////////////////////////////////////
-    // action_matcher
+    // action
     //
-    template<typename Action>
-    struct action_matcher
-      : quant_style<quant_none, 0, false>
+    template<typename BidiIter, typename Actor>
+    struct action
+      : actionable<BidiIter>
     {
-        Action *action_ptr_;
+        action(Actor const &actor)
+          : actionable<BidiIter>()
+          , actor_(actor)
+        {
+        }
 
-        action_matcher()
-          : action_ptr_(&action_())
+        virtual void execute() const
         {
+            proto::context<> ctx;
+            this->actor_.eval(ctx);
         }
 
-        action_matcher(action_matcher const &)
-          : action_ptr_(&action_())
+    private:
+        Actor actor_;
+    };
+
+    
///////////////////////////////////////////////////////////////////////////////
+    // subreg_transform
+    //
+    template<typename Grammar>
+    struct subreg_transform
+      : Grammar
+    {
+        subreg_transform();
+
+        template<typename Expr, typename State, typename Visitor>
+        struct apply
+          : proto::terminal<sub_match<typename State::iterator> >
+        {};
+        
+        template<typename Expr, typename State, typename Visitor>
+        static typename apply<Expr, State, Visitor>::type
+        call(Expr const &expr, State const &state, Visitor &visitor)
         {
+            sub_match<typename State::iterator> const &sub = 
state.sub_matches_[ visitor ];
+            return proto::as_expr(sub);
         }
+    };
 
-        action_matcher &operator =(action_matcher const &)
+    
///////////////////////////////////////////////////////////////////////////////
+    // mark_transform
+    //
+    template<typename Grammar>
+    struct mark_transform
+      : Grammar
+    {
+        mark_transform();
+
+        template<typename Expr, typename State, typename Visitor>
+        struct apply
+          : proto::terminal<sub_match<typename State::iterator> >
+        {};
+        
+        template<typename Expr, typename State, typename Visitor>
+        static typename apply<Expr, State, Visitor>::type
+        call(Expr const &expr, State const &state, Visitor &)
+        {
+            sub_match<typename State::iterator> const &sub = 
state.sub_matches_[ proto::arg(expr).mark_number_ ];
+            return proto::as_expr(sub);
+        }
+    };
+
+    
///////////////////////////////////////////////////////////////////////////////
+    // BindActionArgs
+    //
+    struct BindActionArgs
+      : proto::or_<
+            subreg_transform< proto::terminal<detail::any_matcher> >
+          , mark_transform< detail::mark_tag >
+          , proto::terminal<proto::_>
+          , proto::nary_expr<proto::_, proto::vararg<BindActionArgs> >
+        >
+    {};
+
+    
///////////////////////////////////////////////////////////////////////////////
+    // action_matcher
+    //
+    template<typename Actor>
+    struct action_matcher
+      : quant_style<quant_none, 0, false>
+    {
+        int sub_;
+        Actor actor_;
+
+        action_matcher(Actor const &actor, int sub)
+          : sub_(sub)
+          , actor_(actor)
         {
-            return *this; // no-op
         }
 
         template<typename BidiIter, typename Next>
         bool match(state_type<BidiIter> &state, Next const &next) const
         {
-            Action &action = *this->action_ptr_;
-            typename Action::saved_type saved(action.save());
+            // Bind the arguments
+            typedef typename BindActionArgs::apply<Actor, 
state_type<BidiIter>, int>::type action_type;
+            action<BidiIter, action_type> 
actor(BindActionArgs::call(this->actor_, state, this->sub_));
 
-            // set the action state pointer, so that action_state_cast works 
correctly
-            
core_access<BidiIter>::get_action_state(*state.context_.results_ptr_) = 
state.action_state_;
+            // Put the action in the action list
+            actionable<BidiIter> const **action_list_tail = 
state.action_list_tail_;
+            *state.action_list_tail_ = &actor;
+            state.action_list_tail_ = &actor.next;
 
-            match_results<BidiIter> const &what = *state.context_.results_ptr_;
-            if(!action(what, state.cur_) || !next.match(state))
+            // Match the rest of the pattern
+            if(!next.match(state))
             {
-                action.restore(saved);
+                BOOST_ASSERT(0 == actor.next);
+                // remove action from list
+                *action_list_tail = 0;
+                state.action_list_tail_ = action_list_tail;
                 return false;
             }
 
             return true;
         }
-
-    protected:
-
-        Action &action_()
-        {
-            return *static_cast<Action *>(this);
-        }
     };
 
 }}}

Index: end_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/end_matcher.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- end_matcher.hpp     26 Nov 2005 17:12:25 -0000      1.2
+++ end_matcher.hpp     22 Mar 2007 17:37:16 -0000      1.3
@@ -39,12 +39,19 @@
             // SPECIAL: if there is a match context on the context stack, then
             // this pattern has been nested within another. pop that context 
and
             // continue executing.
-            if(state.context_.prev_context_)
+            if(0 != state.context_.prev_context_)
             {
                 if(!pop_context_match(state))
                 {
                     return false;
                 }
+
+                // record the end of sub-match zero
+                s0.first = s0.begin_;
+                s0.second = tmp;
+                s0.matched = true;
+
+                return true;
             }
             else if(state.flags_.match_all_ && !state.eos() ||
                     state.flags_.match_not_null_ && state.cur_ == s0.begin_)
@@ -57,6 +64,12 @@
             s0.second = tmp;
             s0.matched = true;
 
+            // Now execute any actions that have been queued
+            for(actionable<BidiIter> const *actor = state.action_list_.next; 0 
!= actor; actor = actor->next)
+            {
+                actor->execute();
+            }
+
             return true;
         }
     };

Index: keeper_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/keeper_matcher.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- keeper_matcher.hpp  17 Apr 2006 19:36:52 -0000      1.3
+++ keeper_matcher.hpp  22 Mar 2007 17:37:16 -0000      1.4
@@ -72,12 +72,12 @@
 
             if(!this->xpr_.match(state))
             {
-                reclaim_sub_matches(mem, state);
+                reclaim_sub_matches(mem, state, false);
                 return false;
             }
             else if(next.match(state))
             {
-                reclaim_sub_matches(mem, state);
+                reclaim_sub_matches(mem, state, true);
                 return true;
             }
 

Index: lookahead_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/lookahead_matcher.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- lookahead_matcher.hpp       22 Oct 2006 05:11:38 -0000      1.6
+++ lookahead_matcher.hpp       22 Mar 2007 17:37:16 -0000      1.7
@@ -108,22 +108,22 @@
                 }
                 else if(next.match(state))
                 {
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, true);
                     return true;
                 }
-                reclaim_sub_matches(mem, state);
+                reclaim_sub_matches(mem, state, false);
             }
             else
             {
                 if(!this->xpr_.match(state))
                 {
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, false);
                     return false;
                 }
                 state.cur_ = tmp;
                 if(next.match(state))
                 {
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, true);
                     return true;
                 }
                 restore_sub_matches(mem, state);

Index: lookbehind_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/lookbehind_matcher.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- lookbehind_matcher.hpp      22 Oct 2006 05:11:38 -0000      1.6
+++ lookbehind_matcher.hpp      22 Mar 2007 17:37:16 -0000      1.7
@@ -122,23 +122,23 @@
                 state.cur_ = tmp;
                 if(next.match(state))
                 {
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, true);
                     return true;
                 }
-                reclaim_sub_matches(mem, state);
+                reclaim_sub_matches(mem, state, false);
             }
             else
             {
                 if(!this->xpr_.match(state))
                 {
                     state.cur_ = tmp;
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, false);
                     return false;
                 }
                 BOOST_ASSERT(state.cur_ == tmp);
                 if(next.match(state))
                 {
-                    reclaim_sub_matches(mem, state);
+                    reclaim_sub_matches(mem, state, true);
                     return true;
                 }
                 restore_sub_matches(mem, state);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to