$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r71536 - in trunk: boost/xpressive boost/xpressive/detail boost/xpressive/detail/core libs/xpressive/test
From: eric_at_[hidden]
Date: 2011-04-27 12:21:13
Author: eric_niebler
Date: 2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
New Revision: 71536
URL: http://svn.boost.org/trac/boost/changeset/71536
Log:
replace use of Proto context with transforms
Text files modified: 
   trunk/boost/xpressive/detail/core/adaptor.hpp |     2                                         
   trunk/boost/xpressive/detail/detail_fwd.hpp   |     3                                         
   trunk/boost/xpressive/match_results.hpp       |     4                                         
   trunk/boost/xpressive/regex_actions.hpp       |   140 +++++++++++++++++++++++++++++---------- 
   trunk/boost/xpressive/xpressive_fwd.hpp       |    34 +++++++++                               
   trunk/libs/xpressive/test/test_actions.cpp    |    21 ++++++                                  
   6 files changed, 161 insertions(+), 43 deletions(-)
Modified: trunk/boost/xpressive/detail/core/adaptor.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/adaptor.hpp	(original)
+++ trunk/boost/xpressive/detail/core/adaptor.hpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -49,7 +49,7 @@
 
     virtual bool match(match_state<iterator_type> &state) const
     {
-        typedef typename unwrap_reference<Xpr const>::type xpr_type;
+        typedef typename boost::unwrap_reference<Xpr const>::type xpr_type;
         return implicit_cast<xpr_type &>(this->xpr_).match(state);
     }
 
Modified: trunk/boost/xpressive/detail/detail_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/detail/detail_fwd.hpp	(original)
+++ trunk/boost/xpressive/detail/detail_fwd.hpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -42,8 +42,7 @@
 
     struct action_context;
 
-    template<typename BidiIter>
-    struct replacement_context;
+    struct ReplaceAlgo;
 
     ///////////////////////////////////////////////////////////////////////////////
     // placeholders
Modified: trunk/boost/xpressive/match_results.hpp
==============================================================================
--- trunk/boost/xpressive/match_results.hpp	(original)
+++ trunk/boost/xpressive/match_results.hpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -62,7 +62,6 @@
 #ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
 # include <boost/proto/proto_fwd.hpp>
 # include <boost/proto/traits.hpp>
-# include <boost/proto/eval.hpp>
 #endif
 
 namespace boost { namespace xpressive { namespace detail
@@ -939,8 +938,7 @@
       , mpl::size_t<4>
     ) const
     {
-        detail::replacement_context<BidiIter> ctx(*this);
-        return this->format2_(out, proto::eval(format, ctx));
+        return this->format2_(out, detail::ReplaceAlgo()(format, 0, *this));
     }
 
     /// INTERNAL ONLY
Modified: trunk/boost/xpressive/regex_actions.hpp
==============================================================================
--- trunk/boost/xpressive/regex_actions.hpp	(original)
+++ trunk/boost/xpressive/regex_actions.hpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -42,8 +42,8 @@
 
 // Doxygen can't handle proto :-(
 #ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
-# include <boost/proto/transform/arg.hpp>
-# include <boost/proto/transform/when.hpp>
+# include <boost/proto/core.hpp>
+# include <boost/proto/transform.hpp>
 # include <boost/xpressive/detail/core/matcher/action_matcher.hpp>
 #endif
 
@@ -112,8 +112,9 @@
         struct check_tag
         {};
 
-        struct BindArg : proto::callable
+        struct BindArg
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result;
 
@@ -164,61 +165,51 @@
             BindArgs()(args, 0, what);
         }
 
-        template<typename BidiIter>
-        struct replacement_context
-          : proto::callable_context<replacement_context<BidiIter> const>
-        {
-            replacement_context(match_results<BidiIter> const &what)
-              : what_(what)
-            {}
+        typedef boost::proto::functional::make_expr<proto::tag::function, proto::default_domain> make_function;
+    }
 
+    namespace op
+    {
+        struct at
+        {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result;
 
-            template<typename This>
-            struct result<This(proto::tag::terminal, mark_placeholder const &)>
+            template<typename This, typename Cont, typename Idx>
+            struct result<This(Cont, Idx)>
+              : result<This(Cont const &, Idx)>
             {
-                typedef sub_match<BidiIter> const &type;
             };
 
-            template<typename This>
-            struct result<This(proto::tag::terminal, any_matcher const &)>
+            template<typename This, typename Cont, typename Idx>
+            struct result<This(Cont &, Idx)>
             {
-                typedef sub_match<BidiIter> const &type;
+                typedef typename Cont::reference type;
             };
 
-            template<typename This, typename T>
-            struct result<This(proto::tag::terminal, reference_wrapper<T> const &)>
+            template<typename This, typename Cont, typename Idx>
+            struct result<This(Cont const &, Idx)>
             {
-                typedef T &type;
+                typedef typename Cont::const_reference type;
             };
 
-            sub_match<BidiIter> const &operator ()(proto::tag::terminal, mark_placeholder m) const
-            {
-                return this->what_[m.mark_number_];
-            }
-
-            sub_match<BidiIter> const &operator ()(proto::tag::terminal, any_matcher) const
+            template<typename Cont, typename Idx>
+            typename Cont::reference operator()(Cont &c, Idx idx BOOST_PROTO_DISABLE_IF_IS_CONST(Cont)) const
             {
-                return this->what_[0];
+                return c[idx];
             }
 
-            template<typename T>
-            T &operator ()(proto::tag::terminal, reference_wrapper<T> r) const
+            template<typename Cont, typename Idx>
+            typename Cont::const_reference operator()(Cont const &c, Idx idx) const
             {
-                return r;
+                return c[idx];
             }
-        private:
-            match_results<BidiIter> const &what_;
         };
 
-        typedef boost::proto::functional::make_expr<proto::tag::function, proto::default_domain> make_function;
-    }
-
-    namespace op
-    {
         struct push
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence, typename Value>
@@ -230,6 +221,7 @@
 
         struct push_back
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence, typename Value>
@@ -241,6 +233,7 @@
 
         struct push_front
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence, typename Value>
@@ -252,6 +245,7 @@
 
         struct pop
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence>
@@ -263,6 +257,7 @@
 
         struct pop_back
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence>
@@ -274,6 +269,7 @@
 
         struct pop_front
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             template<typename Sequence>
@@ -285,6 +281,7 @@
 
         struct front
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -310,6 +307,7 @@
 
         struct back
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -335,6 +333,7 @@
 
         struct top
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -360,6 +359,7 @@
 
         struct first
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -378,6 +378,7 @@
 
         struct second
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -396,6 +397,7 @@
 
         struct matched
         {
+            BOOST_PROTO_CALLABLE()
             typedef bool result_type;
 
             template<typename Sub>
@@ -407,6 +409,7 @@
 
         struct length
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -425,6 +428,7 @@
 
         struct str
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -446,6 +450,7 @@
         // associative containers, and strings.
         struct insert
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig, typename EnableIf = void>
             struct result
             {};
@@ -541,6 +546,7 @@
 
         struct make_pair
         {
+            BOOST_PROTO_CALLABLE()
             template<typename Sig>
             struct result {};
 
@@ -560,6 +566,7 @@
         template<typename T>
         struct as
         {
+            BOOST_PROTO_CALLABLE()
             typedef T result_type;
 
             template<typename Value>
@@ -572,6 +579,7 @@
         template<typename T>
         struct static_cast_
         {
+            BOOST_PROTO_CALLABLE()
             typedef T result_type;
 
             template<typename Value>
@@ -584,6 +592,7 @@
         template<typename T>
         struct dynamic_cast_
         {
+            BOOST_PROTO_CALLABLE()
             typedef T result_type;
 
             template<typename Value>
@@ -596,6 +605,7 @@
         template<typename T>
         struct const_cast_
         {
+            BOOST_PROTO_CALLABLE()
             typedef T result_type;
 
             template<typename Value>
@@ -608,6 +618,7 @@
         template<typename T>
         struct construct
         {
+            BOOST_PROTO_CALLABLE()
             typedef T result_type;
 
             T operator()() const
@@ -637,6 +648,7 @@
         template<typename Except>
         struct throw_
         {
+            BOOST_PROTO_CALLABLE()
             typedef void result_type;
 
             void operator()() const
@@ -662,6 +674,31 @@
                 BOOST_THROW_EXCEPTION(Except(a0, a1, a2));
             }
         };
+
+        struct unwrap_reference
+        {
+            BOOST_PROTO_CALLABLE()
+            template<typename Sig>
+            struct result;
+
+            template<typename This, typename Ref>
+            struct result<This(Ref)>
+            {
+                typedef typename boost::unwrap_reference<Ref>::type &type;
+            };
+
+            template<typename This, typename Ref>
+            struct result<This(Ref &)>
+            {
+                typedef typename boost::unwrap_reference<Ref>::type &type;
+            };
+
+            template<typename T>
+            T &operator()(boost::reference_wrapper<T> r) const
+            {
+                return static_cast<T &>(r);
+            }
+        };
     }
 
     template<typename Fun>
@@ -686,6 +723,7 @@
     function<op::str>::type const str = {{}};
     function<op::insert>::type const insert = {{}};
     function<op::make_pair>::type const make_pair = {{}};
+    function<op::unwrap_reference>::type const unwrap_reference = {{}};
 
     template<typename T>
     struct value
@@ -890,8 +928,36 @@
             detail::ignore_unused(xpressive::check);
             detail::ignore_unused(xpressive::let);
         }
-    }
 
+        struct mark_nbr
+        {
+            BOOST_PROTO_CALLABLE()
+            typedef int result_type;
+
+            int operator()(mark_placeholder m) const
+            {
+                return m.mark_number_;
+            }
+        };
+
+        struct ReplaceAlgo
+          : proto::or_<
+                proto::when<
+                    proto::terminal<mark_placeholder>
+                  , op::at(proto::_data, proto::call<mark_nbr(proto::_value)>)
+                >
+              , proto::when<
+                    proto::terminal<any_matcher>
+                  , op::at(proto::_data, proto::size_t<0>)
+                >
+              , proto::when<
+                    proto::terminal<reference_wrapper<proto::_> >
+                  , op::unwrap_reference(proto::_value)
+                >
+              , proto::_default<ReplaceAlgo>
+            >
+        {};
+    }
 }}
 
 #undef UNREF
Modified: trunk/boost/xpressive/xpressive_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/xpressive_fwd.hpp	(original)
+++ trunk/boost/xpressive/xpressive_fwd.hpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -145,6 +145,40 @@
     template<typename T, int I = 0, typename Dummy = proto::is_proto_expr>
     struct placeholder;
 
+    namespace op
+    {
+        struct at;
+        struct push;
+        struct push_back;
+        struct push_front;
+        struct pop;
+        struct pop_back;
+        struct pop_front;
+        struct front;
+        struct back;
+        struct top;
+        struct first;
+        struct second;
+        struct matched;
+        struct length;
+        struct str;
+        struct insert;
+        struct make_pair;
+        template<typename T>
+        struct as;
+        template<typename T>
+        struct static_cast_;
+        template<typename T>
+        struct dynamic_cast_;
+        template<typename T>
+        struct const_cast_;
+        template<typename T>
+        struct construct;
+        template<typename Except>
+        struct throw_;
+        struct unwrap_reference;
+    }
+
     ///////////////////////////////////////////////////////////////////////////////
     // Common typedefs
     //
Modified: trunk/libs/xpressive/test/test_actions.cpp
==============================================================================
--- trunk/libs/xpressive/test/test_actions.cpp	(original)
+++ trunk/libs/xpressive/test/test_actions.cpp	2011-04-27 12:21:12 EDT (Wed, 27 Apr 2011)
@@ -246,6 +246,26 @@
     BOOST_CHECK_EQUAL(build1.get(), 500);
 }
 
+///////////////////////////////////////////////////////////////////////////////
+// test7
+//  Test regex_replace with an xpressive lambda
+void test7()
+{
+    namespace xp = boost::xpressive;
+    using namespace xp;
+
+    std::map<std::string, std::string> env;
+    env["XXX"] = "!!!";
+    env["YYY"] = "???";
+
+    std::string text("This is a %XXX% string %YYY% and stuff.");
+    sregex var = '%' >> (s1 = +_w) >> '%';
+
+    text = regex_replace(text, var, xp::ref(env)[s1]);
+
+    BOOST_CHECK_EQUAL(text, "This is a !!! string ??? and stuff.");
+}
+
 using namespace boost::unit_test;
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -261,6 +281,7 @@
     test->add(BOOST_TEST_CASE(&test4_aux));
     test->add(BOOST_TEST_CASE(&test5));
     test->add(BOOST_TEST_CASE(&test6));
+    test->add(BOOST_TEST_CASE(&test7));
     return test;
 }