$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: eric_at_[hidden]
Date: 2008-03-03 14:47:48
Author: eric_niebler
Date: 2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
New Revision: 43478
URL: http://svn.boost.org/trac/boost/changeset/43478
Log:
second attempt at fixing actions in independent expressions
Added:
   trunk/boost/xpressive/proto/detail/ignore_unused.hpp   (contents, props changed)
Text files modified: 
   trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp         |    46 +++++++++---------------                
   trunk/boost/xpressive/detail/detail_fwd.hpp                       |     4 +-                                      
   trunk/boost/xpressive/detail/static/transforms/as_independent.hpp |    74 +++++++++++++++++++++++++++++++++------ 
   trunk/boost/xpressive/proto/proto_fwd.hpp                         |     4 ++                                      
   trunk/boost/xpressive/proto/transform/make.hpp                    |     4 ++                                      
   trunk/boost/xpressive/regex_compiler.hpp                          |     9 +++-                                    
   6 files changed, 96 insertions(+), 45 deletions(-)
Modified: trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp	(original)
+++ trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -74,34 +74,24 @@
         }
     };
 
-    /////////////////////////////////////////////////////////////////////////////////
-    //// independent_end_matcher
-    ////
-    //struct independent_end_matcher
-    //  : quant_style_assertion
-    //{
-    //    explicit independent_end_matcher(bool pure)
-    //      : pure_(pure)
-    //    {}
-    //    
-    //    template<typename BidiIter, typename Next>
-    //    bool match(match_state<BidiIter> &state, Next const &) const
-    //    {
-    //        if(!this->pure_)
-    //        {
-    //            // Now execute any actions that have been queued
-    //            for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
-    //            {
-    //                actor->execute(state.action_args_);
-    //            }
-    //        }
-    //                    
-    //        return true;
-    //    }
-
-    //private:
-    //    bool pure_;
-    //};
+    ///////////////////////////////////////////////////////////////////////////////
+    // independent_end_matcher
+    //
+    struct independent_end_matcher
+      : quant_style_assertion
+    {
+        template<typename BidiIter, typename Next>
+        bool match(match_state<BidiIter> &state, Next const &) const
+        {
+            // Now execute any actions that have been queued
+            for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
+            {
+                actor->execute(state.action_args_);
+            }
+                        
+            return true;
+        }
+    };
 
 }}}
 
Modified: trunk/boost/xpressive/detail/detail_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/detail/detail_fwd.hpp	(original)
+++ trunk/boost/xpressive/detail/detail_fwd.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -69,7 +69,7 @@
     //
     struct end_matcher;
 
-    //struct independent_end_matcher;
+    struct independent_end_matcher;
 
     struct assert_bos_matcher;
 
@@ -266,7 +266,7 @@
 
     typedef static_xpression<alternate_end_matcher, no_next> alternate_end_xpression;
 
-    //typedef static_xpression<independent_end_matcher, no_next> independent_end_xpression;
+    typedef static_xpression<independent_end_matcher, no_next> independent_end_xpression;
 
     typedef static_xpression<true_matcher, no_next> true_xpression;
 
Modified: trunk/boost/xpressive/detail/static/transforms/as_independent.hpp
==============================================================================
--- trunk/boost/xpressive/detail/static/transforms/as_independent.hpp	(original)
+++ trunk/boost/xpressive/detail/static/transforms/as_independent.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -33,6 +33,61 @@
 
 namespace boost { namespace xpressive { namespace grammar_detail
 {
+    // A grammar that only accepts static regexes that
+    // don't have semantic actions.
+    struct NotHasAction
+      : proto::switch_<struct NotHasActionCases>
+    {};
+
+    struct NotHasActionCases
+    {
+        template<typename Tag, int Dummy = 0>
+        struct case_
+          : proto::nary_expr<Tag, proto::vararg<NotHasAction> >
+        {};
+
+        template<int Dummy>
+        struct case_<proto::tag::terminal, Dummy>
+          : proto::_
+        {};
+
+        template<int Dummy>
+        struct case_<proto::tag::comma, Dummy>
+          : proto::_    // because (set='a','b') can't contain an action
+        {};
+
+        template<int Dummy>
+        struct case_<proto::tag::complement, Dummy>
+          : proto::_    // because in ~X, X can't contain an unscoped action
+        {};
+
+        template<int Dummy>
+        struct case_<detail::lookahead_tag, Dummy>
+          : proto::_    // because actions in lookaheads are scoped
+        {};
+
+        template<int Dummy>
+        struct case_<detail::lookbehind_tag, Dummy>
+          : proto::_    // because actions in lookbehinds are scoped
+        {};
+
+        template<int Dummy>
+        struct case_<detail::keeper_tag, Dummy>
+          : proto::_    // because actions in keepers are scoped
+        {};
+
+        template<int Dummy>
+        struct case_<proto::tag::subscript, Dummy>
+          : proto::subscript<detail::set_initializer_type, _>
+        {}; // only accept set[...], not actions!
+    };
+
+    struct IndependentEndXpression
+      : or_<
+            when<NotHasAction, detail::true_xpression()>
+          , otherwise<detail::independent_end_xpression()>
+        >
+    {};
 
     template<typename Grammar>
     struct as_lookahead : proto::callable
@@ -43,11 +98,11 @@
         struct result<This(Expr, State, Visitor)>
         {
             typedef typename proto::result_of::arg<Expr>::type arg_type;
+            
             typedef
                 typename Grammar::template result<void(
                     arg_type
-                  //, detail::independent_end_xpression
-                  , detail::true_xpression
+                  , typename IndependentEndXpression::result<void(arg_type, proto::ignore_, proto::ignore_)>::type
                   , Visitor
                 )>::type
             xpr_type;
@@ -62,8 +117,7 @@
             return typename result_type::type(
                 Grammar()(
                     proto::arg(expr)
-                  //, detail::independent_end_xpression()
-                  , detail::true_xpression()
+                  , IndependentEndXpression()(proto::arg(expr), proto::ignore, proto::ignore)
                   , visitor
                 )
               , false
@@ -83,8 +137,7 @@
             typedef
                 typename Grammar::template result<void(
                     arg_type
-                  //, detail::independent_end_xpression
-                  , detail::true_xpression
+                  , typename IndependentEndXpression::result<void(arg_type, proto::ignore_, proto::ignore_)>::type
                   , Visitor
                 )>::type
             xpr_type;
@@ -98,8 +151,7 @@
             typedef typename result<void(Expr, State, Visitor)>::xpr_type xpr_type;
             xpr_type const &expr2 = Grammar()(
                 proto::arg(expr)
-              //, detail::independent_end_xpression()
-              , detail::true_xpression()
+              , IndependentEndXpression()(proto::arg(expr), proto::ignore, proto::ignore)
               , visitor
             );
             std::size_t width = expr2.get_width().value();
@@ -119,8 +171,7 @@
             typedef detail::keeper_matcher<
                 typename Grammar::template result<void(
                     arg_type
-                  //, detail::independent_end_xpression
-                  , detail::true_xpression
+                  , typename IndependentEndXpression::result<void(arg_type, proto::ignore_, proto::ignore_)>::type
                   , Visitor
                 )>::type
             > type;
@@ -133,8 +184,7 @@
             return typename result<void(Expr, State, Visitor)>::type(
                 Grammar()(
                     proto::arg(expr)
-                  //, detail::independent_end_xpression()
-                  , detail::true_xpression()
+                  , IndependentEndXpression()(proto::arg(expr), proto::ignore, proto::ignore)
                   , visitor
                 )
             );
Added: trunk/boost/xpressive/proto/detail/ignore_unused.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/xpressive/proto/detail/ignore_unused.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file ignore_unused.hpp
+/// Definintion of ignore_unused, a dummy function for suppressing compiler 
+/// warnings
+//
+//  Copyright 2008 Eric Niebler. Distributed under the Boost
+//  Software License, Version 1.0. (See accompanying file
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_PROTO_DETAIL_IGNORE_UNUSED_HPP_EAN_03_03_2008
+#define BOOST_PROTO_DETAIL_IGNORE_UNUSED_HPP_EAN_03_03_2008
+
+namespace boost { namespace proto
+{
+    namespace detail
+    {
+        template<typename T>
+        inline void ignore_unused(T const &)
+        {}
+    }
+}}
+
+#endif
Modified: trunk/boost/xpressive/proto/proto_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/proto/proto_fwd.hpp	(original)
+++ trunk/boost/xpressive/proto/proto_fwd.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -705,6 +705,10 @@
     namespace exops
     {}
 
+    typedef void ignore_();
+    inline void ignore()
+    {}
+
 }} // namespace boost::proto
 
 #endif
Modified: trunk/boost/xpressive/proto/transform/make.hpp
==============================================================================
--- trunk/boost/xpressive/proto/transform/make.hpp	(original)
+++ trunk/boost/xpressive/proto/transform/make.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -31,6 +31,7 @@
     #include <boost/xpressive/proto/traits.hpp>
     #include <boost/xpressive/proto/args.hpp>
     #include <boost/xpressive/proto/detail/as_lvalue.hpp>
+    #include <boost/xpressive/proto/detail/ignore_unused.hpp>
     #include <boost/xpressive/proto/detail/suffix.hpp>
 
     namespace boost { namespace proto
@@ -337,6 +338,9 @@
             operator ()(Expr const &expr, State const &state, Visitor &visitor) const
             {
                 typedef typename result<void(Expr, State, Visitor)>::type result_type;
+                proto::detail::ignore_unused(expr);
+                proto::detail::ignore_unused(state);
+                proto::detail::ignore_unused(visitor);
                 return detail::construct<result_type>(
                     #define TMP(Z, M, DATA) detail::as_lvalue(when<_, BOOST_PP_CAT(A, M)>()(expr, state, visitor))
                     BOOST_PP_ENUM(N, TMP, DATA)
Modified: trunk/boost/xpressive/regex_compiler.hpp
==============================================================================
--- trunk/boost/xpressive/regex_compiler.hpp	(original)
+++ trunk/boost/xpressive/regex_compiler.hpp	2008-03-03 14:47:47 EST (Mon, 03 Mar 2008)
@@ -320,7 +320,8 @@
             negative = true; // fall-through
         case token_positive_lookahead:
             lookahead = true;
-            //seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+            // If we ever support actions in dynamic regexes, then this should 
+            // be independent_end_matcher:
             seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
             break;
 
@@ -328,13 +329,15 @@
             negative = true; // fall-through
         case token_positive_lookbehind:
             lookbehind = true;
-            //seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+            // If we ever support actions in dynamic regexes, then this should 
+            // be independent_end_matcher:
             seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
             break;
 
         case token_independent_sub_expression:
             keeper = true;
-            //seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+            // If we ever support actions in dynamic regexes, then this should 
+            // be independent_end_matcher:
             seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
             break;