$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: eric_at_[hidden]
Date: 2007-11-08 17:07:40
Author: eric_niebler
Date: 2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
New Revision: 40945
URL: http://svn.boost.org/trac/boost/changeset/40945
Log:
port toy_spirit3 to proto3
Text files modified: 
   branches/proto/v3/boost/xpressive/proto3/traits.hpp          |    15 ++++                                    
   branches/proto/v3/boost/xpressive/proto3/transform.hpp       |     2                                         
   branches/proto/v3/boost/xpressive/proto3/transform/apply.hpp |     9 +++                                     
   branches/proto/v3/boost/xpressive/proto3/transform/case.hpp  |   105 +++++++++++++++++++++++++++++---------- 
   branches/proto/v3/libs/xpressive/proto3/test/toy_spirit3.cpp |    46 ++++++++--------                        
   5 files changed, 123 insertions(+), 54 deletions(-)
Modified: branches/proto/v3/boost/xpressive/proto3/traits.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/traits.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto3/traits.hpp	2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
@@ -345,10 +345,21 @@
         struct as_expr<T, Domain, typename T::proto_is_expr_>
         {
             typedef typename T::proto_derived_expr type;
+            typedef T const &result_type;
+
+            static T const &call(T const &t)
+            {
+                return t;
+            }
+        };
+
+        template<typename T, typename Domain>
+        struct as_expr<T &, Domain, typename T::proto_is_expr_>
+        {
+            typedef typename T::proto_derived_expr type;
             typedef T &result_type;
 
-            template<typename T2>
-            static result_type call(T2 &&t)
+            static T &call(T &t)
             {
                 return t;
             }
Modified: branches/proto/v3/boost/xpressive/proto3/transform.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/transform.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto3/transform.hpp	2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 /// \file transform.hpp
-/// Definition of case_ transform.
+/// Includes all the transforms
 //
 //  Copyright 2007 Eric Niebler. Distributed under the Boost
 //  Software License, Version 1.0. (See accompanying file
Modified: branches/proto/v3/boost/xpressive/proto3/transform/apply.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/transform/apply.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto3/transform/apply.hpp	2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
@@ -9,6 +9,7 @@
 #ifndef BOOST_PROTO3_TRANSFORM_APPLY_HPP_EAN_11_02_2007
 #define BOOST_PROTO3_TRANSFORM_APPLY_HPP_EAN_11_02_2007
 
+#include <boost/type_traits.hpp>
 #include <boost/utility/result_of.hpp>
 #include <boost/xpressive/proto3/proto_fwd.hpp>
 #include <boost/xpressive/proto3/traits.hpp>
@@ -18,6 +19,11 @@
 
     namespace transform
     {
+        template<typename T>
+        typename add_reference<T>::type as_lvalue(T &&t)
+        {
+            return t;
+        }
 
         template<typename Trans>
         struct apply_<Trans>
@@ -88,10 +94,11 @@
             static typename apply<Expr, State, Visitor>::type
             call(Expr const &expr, State const &state, Visitor &visitor)
             {
+                typedef typename case_<_, VisitorTfx>::template apply<Expr, State, Visitor>::type visitor_type;
                 return Trans::call(
                     case_<_, ExprTfx>::call(expr, state, visitor)
                   , case_<_, StateTfx>::call(expr, state, visitor)
-                  , case_<_, VisitorTfx>::call(expr, state, visitor)
+                  , const_cast<visitor_type &>(as_lvalue(case_<_, VisitorTfx>::call(expr, state, visitor)))
                 );
             }
         };
Modified: branches/proto/v3/boost/xpressive/proto3/transform/case.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/transform/case.hpp	(original)
+++ branches/proto/v3/boost/xpressive/proto3/transform/case.hpp	2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
@@ -125,33 +125,59 @@
                 return Type(args...);
             }
 
-            template<typename TransformCategory, typename Return, typename... Args>
-            struct case_impl
-              : raw_transform
+            template<
+                typename Expr
+              , typename State
+              , typename Visitor
+              , typename TransformCategory
+              , typename Return
+              , typename... Args
+            >
+            struct apply_
             {
-                template<typename Expr, typename State, typename Visitor>
-                struct apply
-                  : apply_lambda_<Return, Expr, State, Visitor>
-                {};
-
-                template<typename Expr, typename State, typename Visitor>
-                static typename apply<Expr, State, Visitor>::type
-                call(Expr const &expr, State const &state, Visitor &visitor)
+                typedef typename apply_lambda_<Return, Expr, State, Visitor>::type type;
+
+                static type call(Expr const &expr, State const &state, Visitor &visitor)
                 {
-                    typedef typename apply<Expr, State, Visitor>::type type;
-                    return detail::construct_<type>(case_<_, Args>::call(expr, state, visitor)...);
+                    return detail::construct_<type>(
+                        case_<_, Args>::call(expr, state, visitor)...
+                    );
                 }
             };
 
-            template<typename Return, typename... Args>
-            struct case_impl<function_transform, Return, Args...>
-              : bind<Return, Args...>
-            {};
+            template<
+                typename Expr
+              , typename State
+              , typename Visitor
+              , typename Return
+              , typename... Args
+            >
+            struct apply_<Expr, State, Visitor, function_transform, Return, Args...>
+            {
+                typedef typename bind<Return, Args...>::template apply<Expr, State, Visitor>::type type;
 
-            template<typename Return, typename... Args>
-            struct case_impl<raw_transform, Return, Args...>
-              : apply_<Return, Args...>
-            {};
+                static type call(Expr const &expr, State const &state, Visitor &visitor)
+                {
+                    return bind<Return, Args...>::call(expr, state, visitor);
+                }
+            };
+
+            template<
+                typename Expr
+              , typename State
+              , typename Visitor
+              , typename Return
+              , typename... Args
+            >
+            struct apply_<Expr, State, Visitor, raw_transform, Return, Args...>
+            {
+                typedef typename transform::apply_<Return, Args...>::template apply<Expr, State, Visitor>::type type;
+
+                static type call(Expr const &expr, State const &state, Visitor &visitor)
+                {
+                    return transform::apply_<Return, Args...>::call(expr, state, visitor);
+                }
+            };
 
         }
 
@@ -169,22 +195,47 @@
         // (possibly lambda) type and constructor arguments.
         template<typename Grammar, typename Return, typename... Args>
         struct case_<Grammar, Return(Args...)>
-          : detail::case_impl<typename transform_category<Return>::type, Return, Args...>
+          : raw_transform
         {
             typedef typename Grammar::proto_base_expr proto_base_expr;
+
+            template<typename Expr, typename State, typename Visitor>
+            struct apply
+              : detail::apply_<Expr, State, Visitor, typename transform_category<Return>::type, Return, Args...>
+            {};
+
+            // BUGBUG makes a temporary
+            template<typename Expr, typename State, typename Visitor>
+            static typename apply<Expr, State, Visitor>::type
+            call(Expr const &expr, State const &state, Visitor &visitor)
+            {
+                return apply<Expr, State, Visitor>::call(expr, state, visitor);
+            }
         };
 
         template<typename Grammar, typename Return, typename... Args>
         struct case_<Grammar, Return(*)(Args...)>
-          : detail::case_impl<typename transform_category<Return>::type, Return, Args...>
+          : raw_transform
         {
             typedef typename Grammar::proto_base_expr proto_base_expr;
+
+            template<typename Expr, typename State, typename Visitor>
+            struct apply
+              : detail::apply_<Expr, State, Visitor, typename transform_category<Return>::type, Return, Args...>
+            {};
+
+            template<typename Expr, typename State, typename Visitor>
+            static typename apply<Expr, State, Visitor>::type
+            call(Expr const &expr, State const &state, Visitor &visitor)
+            {
+                return apply<Expr, State, Visitor>::call(expr, state, visitor);
+            }
         };
 
-        template<typename Trans>
-        struct typeof_
-          : case_<_, Trans>
-        {};
+        //template<typename Trans>
+        //struct typeof_
+        //  : case_<_, Trans>
+        //{};
 
     }
 
Modified: branches/proto/v3/libs/xpressive/proto3/test/toy_spirit3.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto3/test/toy_spirit3.cpp	(original)
+++ branches/proto/v3/libs/xpressive/proto3/test/toy_spirit3.cpp	2007-11-08 17:07:40 EST (Thu, 08 Nov 2007)
@@ -7,22 +7,25 @@
 
 #include <cctype>
 #include <string>
+#include <cstring>
 #include <iomanip>
 #include <iostream>
+#include <boost/version.hpp>
 #include <boost/assert.hpp>
 #include <boost/mpl/assert.hpp>
 #include <boost/utility/result_of.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/xpressive/proto3/proto.hpp>
-#include <boost/xpressive/proto3/transform2.hpp>
+#include <boost/xpressive/proto3/transform.hpp>
 #if BOOST_VERSION < 103500
 # include <boost/spirit/fusion/algorithm/for_each.hpp>
 # include <boost/spirit/fusion/algorithm/fold.hpp>
 # include <boost/spirit/fusion/algorithm/any.hpp>
 #else
-#include <boost/fusion/include/for_each.hpp>
-#include <boost/fusion/include/fold.hpp>
-#include <boost/fusion/include/any.hpp>
+# include <boost/fusion/include/for_each.hpp>
+# include <boost/fusion/include/fold.hpp>
+# include <boost/fusion/include/cons.hpp>
+# include <boost/fusion/include/any.hpp>
 #endif
 #include <boost/test/unit_test.hpp>
 
@@ -154,30 +157,29 @@
     // The no-case directive
     struct no_case_tag {};
 
+    struct True : mpl::true_ {};
+
     // remove_case specializations for stripping case-sensitivity from parsers
     template<typename T, typename CaseSensitive>
-    struct remove_case;
-
-    template<typename T>
-    struct remove_case<T, mpl::false_>
+    struct remove_case
     {
         typedef T type;
     };
 
     template<>
-    struct remove_case<char, mpl::true_>
+    struct remove_case<char, True>
     {
         typedef ichar type;
     };
 
     template<>
-    struct remove_case<char const *, mpl::true_>
+    struct remove_case<char const *, True>
     {
         typedef istr type;
     };
 
     template<>
-    struct remove_case<char_range, mpl::true_>
+    struct remove_case<char_range, True>
     {
         typedef ichar_range type;
     };
@@ -189,6 +191,7 @@
     {
         using namespace proto;
         using namespace fusion;
+        using namespace transform;
 
         struct SpiritExpr;
 
@@ -221,35 +224,32 @@
           : or_<
                 case_< AnyChar,          _arg >
               , case_< CharLiteral,      remove_case<char, _visitor>(_arg) >
-              , case_< CharParser,       remove_case<char, _visitor>(_arg_c<0, _arg1>)> // char_('a')
+              , case_< CharParser,       remove_case<char, _visitor>(_arg(_arg1))> // char_('a')
               , case_< NTBSLiteral,      remove_case<char const *, _visitor>(_arg) >
-              , case_< CharRangeParser,  remove_case<char_range, _visitor>(_arg_c<0, _arg1>, _arg_c<0, _arg2>)> // char_('a','z')
+              , case_< CharRangeParser,  remove_case<char_range, _visitor>(_arg(_arg1), _arg(_arg2))> // char_('a','z')
             >
         {};
 
-        template<typename Grammar>
         struct FoldToList
-          : reverse_fold_tree<Grammar, nil(), cons<SpiritExpr, _state>(SpiritExpr, _state)>
+          : reverse_fold_tree<_, nil(), cons<SpiritExpr, _state>(SpiritExpr, _state)>
         {};
 
-        struct AltList : FoldToList< bitwise_or<_, _> > {};
-        struct SeqList : FoldToList< shift_right<_, _> > {};
-
         // sequence rule folds all >>'s together into a list
         // and wraps the result in a sequence<> wrapper
         struct SpiritSequence
-          : case_< shift_right<SpiritExpr, SpiritExpr>,  sequence<SeqList>(SeqList)  >
+          : case_< shift_right<SpiritExpr, SpiritExpr>,  sequence<FoldToList>(FoldToList)  >
         {};
 
         // alternate rule folds all |'s together into a list
         // and wraps the result in a alternate<> wrapper
         struct SpiritAlternate
-          : case_< bitwise_or<SpiritExpr, SpiritExpr>,   alternate<AltList>(AltList) >
+          : case_< bitwise_or<SpiritExpr, SpiritExpr>,   alternate<FoldToList>(FoldToList) >
         {};
 
+
         // Directives such as no_case are handled here
         struct SpiritDirective
-          : case_< subscript<NoCase, SpiritExpr>, apply_<SpiritExpr, _right, _state, mpl::true_()> >
+          : case_< subscript<NoCase, SpiritExpr>, SpiritExpr(_right, _state, True()) >
         {};
 
         // A SpiritExpr is an alternate, a sequence, a directive or a terminal
@@ -303,9 +303,9 @@
 
     template<typename Iterator>
     struct parser
-      : with_reset<Iterator, parser<Iterator> >
+      : spirit2::with_reset<Iterator, parser<Iterator> >
     {
-        typedef with_reset<Iterator, parser<Iterator> > with_reset;
+        typedef spirit2::with_reset<Iterator, parser<Iterator> > with_reset;
 
         parser(Iterator begin, Iterator end)
           : with_reset(begin, end)