Update of /cvsroot/boost/boost/boost/xpressive/detail/static/transforms
In directory 
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4470/boost/xpressive/detail/static/transforms

Modified Files:
        as_quantifier.hpp transform.hpp 
Added Files:
        as_set.hpp 
Log Message:
as_set and as_list_set transforms, and set complement

--- NEW FILE: as_set.hpp ---
///////////////////////////////////////////////////////////////////////////////
// as_set.hpp
//
//  Copyright 2004 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_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SET_HPP_EAN_04_05_2007
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SET_HPP_EAN_04_05_2007

// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#include <boost/mpl/sizeof.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/static/static.hpp>
#include <boost/xpressive/proto/proto.hpp>
#include <boost/xpressive/proto/context.hpp>
#include <boost/xpressive/proto/transform/arg.hpp>

namespace boost { namespace xpressive { namespace detail
{

    template<typename Grammar>
    struct increment
      : Grammar
    {
        template<typename Expr, typename State, typename Visitor>
        struct apply
          : mpl::next<typename Grammar::template apply<Expr, State, 
Visitor>::type>
        {};
    };

    struct SetSize
      : proto::or_<
            increment<proto::trans::left<proto::comma<SetSize, 
proto::terminal<char> > > >
          , proto::trans::always<proto::assign<set_initializer_type, 
proto::terminal<char> >, mpl::int_<1> >
        >
    {};

    template<typename Char>
    struct SetFillContext
      : proto::callable_context<SetFillContext<Char> >
    {
        explicit SetFillContext(Char *buf)
          : buffer(buf)
          , index(0)
        {}

        typedef xpressive::detail::set_initializer result_type;

        template<typename Tag, typename Left, typename Right>
        result_type operator()(Tag, Left const &left, Right const &ch)
        {
            this->buffer[this->index++] = proto::arg(ch);
            return proto::eval(left, *this);
        }

        Char *buffer;
        int index;
    };

    template<typename Grammar>
    struct as_list_set
      : Grammar
    {
        as_list_set();

        template<typename Expr, typename State, typename Visitor>
        struct apply
        {
            typedef set_matcher<
                typename Visitor::traits_type
              , SetSize::apply<Expr, State, Visitor>::type::value
            > type;
        };

        template<typename Expr, typename State, typename Visitor>
        static typename apply<Expr, State, Visitor>::type
        call(Expr const &expr, State const &state, Visitor &visitor)
        {
            typename apply<Expr, State, Visitor>::type set(visitor.traits());
            SetFillContext<typename Visitor::char_type> ctx(set.set_);
            proto::eval(expr, ctx);
            int const size = SetSize::apply<Expr, State, Visitor>::type::value;
            for(int i = 0; i < size; ++i)
            {
                set.set_[i] = visitor.traits().translate(set.set_[i]);
            }
            return set;
        }
    };

    
///////////////////////////////////////////////////////////////////////////////
    // charset_context
    //
    template<typename Grammar, typename CharSet, typename Visitor>
    struct charset_context
    {
        template<typename Expr, typename Tag>
        struct eval_
        {
            typedef void result_type;
            void operator()(Expr const &expr, charset_context const &ctx) const
            {
                ctx.set(Grammar::call(expr, end_xpression(), ctx.visitor_));
            }
        };

        template<typename Expr>
        struct eval_<Expr, proto::tag::bitwise_or>
        {
            typedef void result_type;
            void operator()(Expr const &expr, charset_context const &ctx) const
            {
                proto::eval(proto::left(expr), ctx);
                proto::eval(proto::right(expr), ctx);
            }
        };

        // Gah, this is to work around a MSVC bug.
        template<typename Expr>
        struct eval
          : eval_<Expr, typename Expr::tag_type>
        {};

        typedef typename Visitor::traits_type traits_type;
        typedef typename CharSet::char_type char_type;
        typedef typename CharSet::icase_type icase_type;

        explicit charset_context(CharSet &charset, Visitor &visitor)
          : charset_(charset)
          , visitor_(visitor)
        {}

        template<bool Not>
        void set(literal_matcher<traits_type, icase_type::value, Not> const 
&ch) const
        {
            // BUGBUG fixme!
            BOOST_MPL_ASSERT_NOT((mpl::bool_<Not>));
            set_char(this->charset_.charset_, ch.ch_, this->visitor_.traits(), 
icase_type());
        }

        void set(range_matcher<traits_type, icase_type::value> const &rg) const
        {
            // BUGBUG fixme!
            BOOST_ASSERT(!rg.not_);
            set_range(this->charset_.charset_, rg.ch_min_, rg.ch_max_, 
this->visitor_.traits(), icase_type());
        }

        template<int Size>
        void set(set_matcher<traits_type, Size> const &set_) const
        {
            // BUGBUG fixme!
            BOOST_ASSERT(!set_.not_);
            for(int i=0; i<Size; ++i)
            {
                set_char(this->charset_.charset_, set_.set_[i], 
this->visitor_.traits(), icase_type::value);
            }
        }

        void set(posix_charset_matcher<traits_type> const &posix) const
        {
            set_class(this->charset_.charset_, posix.mask_, posix.not_, 
this->visitor_.traits());
        }

        CharSet &charset_;
        Visitor &visitor_;
    };

    
///////////////////////////////////////////////////////////////////////////////
    //
    template<typename Grammar>
    struct as_set
      : Grammar
    {
        as_set();

        template<typename, typename, typename Visitor>
        struct apply
        {
            typedef typename Visitor::char_type char_type;

            // if sizeof(char_type)==1, merge everything into a basic_chset
            // BUGBUG this is not optimal.
            typedef typename mpl::if_<
                mpl::equal_to<mpl::sizeof_<char_type>, mpl::size_t<1> >
              , basic_chset<char_type>
              , compound_charset<typename Visitor::traits_type>
            >::type charset_type;

            typedef charset_matcher<
                typename Visitor::traits_type
              , Visitor::icase_type::value
              , charset_type
            > type;
        };

        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<Expr, State, Visitor>::type set_type;
            set_type matcher;
            charset_context<Grammar, set_type, Visitor> ctx(matcher, visitor);
            // Walks the tree and fills in the charset
            proto::eval(expr, ctx);
            return matcher;
        }
    };

    template<typename Grammar>
    struct inverse
      : Grammar
    {
        inverse();

        template<typename Expr, typename State, typename Visitor>
        struct apply
          : Grammar::template apply<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)
        {
            typename apply<Expr, State, Visitor>::type set =
                Grammar::call(expr, state, visitor);
            set.inverse();
            return set;
        }
    };

}}}

#endif

Index: as_quantifier.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/static/transforms/as_quantifier.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- as_quantifier.hpp   5 Apr 2007 06:41:13 -0000       1.3
+++ as_quantifier.hpp   5 Apr 2007 20:49:10 -0000       1.4
@@ -130,7 +130,7 @@
             typedef typename proto::result_of::arg<Expr>::type arg_type;
             typename InsertMark::apply<arg_type, State, Visitor>::type const &
                 marked_sub = InsertMark::call(proto::arg(expr), state, 
visitor);
-            
+
             // Get the mark_number from the begin_mark_matcher
             int mark_number = proto::arg(proto::left(marked_sub)).mark_number_;
             BOOST_ASSERT(0 != mark_number);

Index: transform.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/static/transforms/transform.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- transform.hpp       5 Apr 2007 06:41:13 -0000       1.3
+++ transform.hpp       5 Apr 2007 20:49:11 -0000       1.4
@@ -14,6 +14,7 @@
 #endif
 
 #include <boost/mpl/not.hpp>
+#include <boost/xpressive/detail/detail_fwd.hpp>
 #include <boost/xpressive/proto/proto.hpp>
 #include <boost/xpressive/proto/transform/fold.hpp>
 #include <boost/xpressive/detail/static/transforms/as_matcher.hpp>
@@ -21,6 +22,7 @@
 #include <boost/xpressive/detail/static/transforms/as_sequence.hpp>
 #include <boost/xpressive/detail/static/transforms/as_quantifier.hpp>
 #include <boost/xpressive/detail/static/transforms/as_marker.hpp>
+#include <boost/xpressive/detail/static/transforms/as_set.hpp>
 #include <boost/xpressive/proto/transform/arg.hpp>
 #include <boost/xpressive/proto/transform/compose.hpp>
 
@@ -37,7 +39,7 @@
     {};
 
     struct Grammar;
-    
+
     struct Sequence
       : proto::right_shift<Grammar, Grammar>
     {};
@@ -81,22 +83,41 @@
         >
     {};
 
+    struct ListSet
+      : proto::or_<
+            proto::comma<ListSet, proto::terminal<char> >
+          , proto::assign<set_initializer_type, proto::terminal<char> >
+        >
+    {};
+
+    struct SetMatcher
+      : proto::or_<
+            as_list_set<ListSet>
+          , proto::trans::right<proto::subscript<set_initializer_type, 
as_set<Grammar> > >
+        >
+    {};
+
     // These sub-expressions generate simple matcher types
     // that must be placed in sequence.
-    struct NonSequence
+    struct Matchers
       : proto::or_<
             as_matcher<Terminal>
           , as_alternate<Alternate>
+
           , as_simple_quantifier<SimpleGreedyQuantifier, true>
           , 
proto::trans::arg<proto::unary_minus<as_simple_quantifier<SimpleGreedyQuantifier,
 false> > >
+
+          , SetMatcher
+          , inverse<proto::trans::arg<proto::complement<SetMatcher> > >
         >
     {};
 
     // These sub-expressions require further processing.
-    struct Transforms
+    struct Composites
       : proto::or_<
             as_default_quantifier<DefaultGreedyQuantifier, true>
           , 
proto::trans::arg<proto::unary_minus<as_default_quantifier<DefaultGreedyQuantifier,
 false> > >
+
           , as_marker<Mark>
         >
     {};
@@ -104,8 +125,8 @@
     struct Grammar
       : proto::or_<
             proto::trans::reverse_fold<Sequence>
-          , proto::trans::compose<Transforms, Grammar>
-          , in_sequence<NonSequence>
+          , proto::trans::compose<Composites, Grammar>
+          , in_sequence<Matchers>
         >
     {};
 
@@ -113,6 +134,7 @@
     typename Grammar::apply<Expr, end_xpression, Visitor>::type
     transform(Expr const &expr, Visitor &visitor)
     {
+        BOOST_MPL_ASSERT((proto::matches<Expr, Grammar>));
         return Grammar::call(expr, end_xpression(), visitor);
     }
 


-------------------------------------------------------------------------
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