|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-02-27 13:48:23
Author: eric_niebler
Date: 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
New Revision: 43421
URL: http://svn.boost.org/trac/boost/changeset/43421
Log:
partially revert breaking change to independent sub-expressions until I can make a proper fix
Text files modified:
trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp | 18 ++++-
trunk/boost/xpressive/detail/static/transforms/as_independent.hpp | 52 +++++++++++++--
trunk/boost/xpressive/proto/context/callable.hpp | 126 +++++++++++++++++++++++++++++++++++++--
trunk/boost/xpressive/proto/context/default.hpp | 3
trunk/boost/xpressive/proto/ref.hpp | 6 +
trunk/boost/xpressive/proto/transform/pass_through.hpp | 16 +++-
trunk/boost/xpressive/regex_compiler.hpp | 9 +
7 files changed, 198 insertions(+), 32 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-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -80,17 +80,27 @@
struct independent_end_matcher
: quant_style_assertion
{
+ explicit independent_end_matcher(bool pure)
+ : pure_(pure)
+ {}
+
template<typename BidiIter, typename Next>
static bool match(match_state<BidiIter> &state, Next const &)
{
- // Now execute any actions that have been queued
- for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
+ if(!this->pure_)
{
- actor->execute(state.action_args_);
+ // 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_;
};
}}}
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-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -43,17 +43,29 @@
struct result<This(Expr, State, Visitor)>
{
typedef typename proto::result_of::arg<Expr>::type arg_type;
- typedef detail::lookahead_matcher<
- typename Grammar::template result<void(arg_type, detail::independent_end_xpression, Visitor)>::type
- > type;
+ typedef
+ typename Grammar::template result<void(
+ arg_type
+ //, detail::independent_end_xpression
+ , detail::true_xpression
+ , Visitor
+ )>::type
+ xpr_type;
+ typedef detail::lookahead_matcher<xpr_type> type;
};
template<typename Expr, typename State, typename Visitor>
typename result<void(Expr, State, Visitor)>::type
operator ()(Expr const &expr, State const &, Visitor &visitor) const
{
- return typename result<void(Expr, State, Visitor)>::type(
- Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor)
+ typedef result<void(Expr, State, Visitor)> result_type;
+ return typename result_type::type(
+ Grammar()(
+ proto::arg(expr)
+ //, detail::independent_end_xpression()
+ , detail::true_xpression()
+ , visitor
+ )
, false
);
}
@@ -68,7 +80,14 @@
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, Visitor)>::type xpr_type;
+ typedef
+ typename Grammar::template result<void(
+ arg_type
+ //, detail::independent_end_xpression
+ , detail::true_xpression
+ , Visitor
+ )>::type
+ xpr_type;
typedef detail::lookbehind_matcher<xpr_type> type;
};
@@ -77,7 +96,12 @@
operator ()(Expr const &expr, State const &, Visitor &visitor) const
{
typedef typename result<void(Expr, State, Visitor)>::xpr_type xpr_type;
- xpr_type const &expr2 = Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor);
+ xpr_type const &expr2 = Grammar()(
+ proto::arg(expr)
+ //, detail::independent_end_xpression()
+ , detail::true_xpression()
+ , visitor
+ );
std::size_t width = expr2.get_width().value();
return detail::lookbehind_matcher<xpr_type>(expr2, width, false);
}
@@ -93,7 +117,12 @@
{
typedef typename proto::result_of::arg<Expr>::type arg_type;
typedef detail::keeper_matcher<
- typename Grammar::template result<void(arg_type, detail::independent_end_xpression, Visitor)>::type
+ typename Grammar::template result<void(
+ arg_type
+ //, detail::independent_end_xpression
+ , detail::true_xpression
+ , Visitor
+ )>::type
> type;
};
@@ -102,7 +131,12 @@
operator ()(Expr const &expr, State const &, Visitor &visitor) const
{
return typename result<void(Expr, State, Visitor)>::type(
- Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor)
+ Grammar()(
+ proto::arg(expr)
+ //, detail::independent_end_xpression()
+ , detail::true_xpression()
+ , visitor
+ )
);
}
};
Modified: trunk/boost/xpressive/proto/context/callable.hpp
==============================================================================
--- trunk/boost/xpressive/proto/context/callable.hpp (original)
+++ trunk/boost/xpressive/proto/context/callable.hpp 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -4,8 +4,8 @@
/// Definintion of callable_context\<\>, an evaluation context for
/// proto::eval() that explodes each node and calls the derived context
/// type with the expressions constituents. If the derived context doesn't
- /// have an overload that handles this node, fall-back to the default_context.
- /// TODO: make the fall-back configurable!
+ /// have an overload that handles this node, fall back to some other
+ /// context.
//
// Copyright 2008 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -20,6 +20,7 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
+ #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
@@ -55,8 +56,18 @@
namespace context
{
- /// callable_eval
+ /// \brief A BinaryFunction that accepts a Proto expression and a
+ /// callable context and calls the context with the expression tag
+ /// and children as arguments, effectively fanning the expression
+ /// out.
///
+ /// <tt>callable_eval\<\></tt> requires that \c Context is a
+ /// PolymorphicFunctionObject that can be invoked with \c Expr's
+ /// tag and children as expressions, as follows:
+ ///
+ /// \code
+ /// context(Expr::proto_tag(), arg_c\<0\>(expr), arg_c\<1\>(expr), ...)
+ /// \endcode
template<
typename Expr
, typename Context
@@ -65,16 +76,90 @@
struct callable_eval
{};
- /// callable_context
+ /// \brief An evaluation context adaptor that makes authoring a
+ /// context a simple matter of writing function overloads, rather
+ /// then writing template specializations.
+ ///
+ /// <tt>callable_context\<\></tt> is a base class that implements
+ /// the context protocol by passing fanned-out expression nodes to
+ /// the derived context, making it easy to customize the handling
+ /// of expression types by writing function overloads. Only those
+ /// expression types needing special handling require explicit
+ /// handling. All others are dispatched to a user-specified
+ /// default context, \c DefaultCtx.
+ ///
+ /// <tt>callable_context\<\></tt> is defined simply as:
+ ///
+ /// \code
+ /// template<typename Context, typename DefaultCtx = default_context>
+ /// struct callable_context
+ /// {
+ /// template<typename Expr, typename ThisContext = Context>
+ /// struct eval
+ /// : mpl::if_<
+ /// is_expr_handled_<Expr, Context> // For exposition
+ /// , callable_eval<Expr, ThisContext>
+ /// , typename DefaultCtx::template eval<Expr, Context>
+ /// >::type
+ /// {};
+ /// };
+ /// \endcode
+ ///
+ /// The Boolean metafunction <tt>is_expr_handled_\<\></tt> uses
+ /// metaprogramming tricks to determine whether \c Context has
+ /// an overloaded function call operator that accepts the
+ /// fanned-out constituents of an expression of type \c Expr.
+ /// If so, the handling of the expression is dispatched to
+ /// <tt>callable_eval\<\></tt>. If not, it is dispatched to
+ /// the user-specified \c DefaultCtx.
+ ///
+ /// Below is an example of how to use <tt>callable_context\<\></tt>:
+ ///
+ /// \code
+ /// // An evaluation context that increments all
+ /// // integer terminals in-place.
+ /// struct increment_ints
+ /// : callable_context<
+ /// increment_ints const // derived context
+ /// , null_context const // fall-back context
+ /// >
+ /// {
+ /// typedef void result_type;
+ ///
+ /// // Handle int terminals here:
+ /// void operator()(proto::tag::terminal, int &i) const
+ /// {
+ /// ++i;
+ /// }
+ /// };
+ /// \endcode
///
+ /// With \c increment_ints, we can do the following:
+ ///
+ /// \code
+ /// literal<int> i = 0, j = 10;
+ /// proto::eval( i - j * 3.14, increment_ints() );
+ ///
+ /// assert( i.get() == 1 && j.get() == 11 );
+ /// \endcode
template<
typename Context
, typename DefaultCtx BOOST_PROTO_FOR_DOXYGEN_ONLY(= default_context)
>
struct callable_context
{
- /// callable_context::eval
+ /// A BinaryFunction that accepts an \c Expr and a
+ /// \c Context, and either fans out the expression and passes
+ /// it to the context, or else hands off the expression to
+ /// \c DefaultCtx.
///
+ /// If \c Context is a PolymorphicFunctionObject such that
+ /// it can be invoked with the tag and children of \c Expr,
+ /// as <tt>ctx(Expr::proto_tag(), arg_c\<0\>(expr), arg_c\<1\>(expr)...)</tt>,
+ /// then <tt>eval\<Expr, ThisContext\></tt> inherits from
+ /// <tt>callable_eval\<Expr, ThisContext\></tt>. Otherwise,
+ /// <tt>eval\<Expr, ThisContext\></tt> inherits from
+ /// <tt>DefaultCtx::eval\<Expr, Context\></tt>.
template<typename Expr, typename ThisContext = Context>
struct eval
: mpl::if_<
@@ -87,7 +172,7 @@
}
#define BOOST_PROTO_ARG_N_TYPE(Z, N, Expr) \
- typename proto::result_of::arg_c<Expr, N>::const_reference \
+ typedef typename proto::result_of::arg_c<Expr, N>::const_reference BOOST_PP_CAT(arg, N); \
/**/
#define BOOST_PROTO_ARG_N(Z, N, expr) \
@@ -120,8 +205,14 @@
: remove_cv<Context>::type
{
callable_context_wrapper();
- typedef private_type_ const &(*pointer_to_function)(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(ARG_COUNT), detail::dont_care BOOST_PP_INTERCEPT));
- operator pointer_to_function() const;
+ typedef
+ private_type_ const &fun_type(
+ BOOST_PP_ENUM_PARAMS(
+ BOOST_PP_INC(ARG_COUNT)
+ , detail::dont_care BOOST_PP_INTERCEPT
+ )
+ );
+ operator fun_type *() const;
};
#endif
@@ -149,18 +240,35 @@
namespace context
{
+ /// \brief A BinaryFunction that accepts a Proto expression and a
+ /// callable context and calls the context with the expression tag
+ /// and children as arguments, effectively fanning the expression
+ /// out.
+ ///
+ /// <tt>callable_eval\<\></tt> requires that \c Context is a
+ /// PolymorphicFunctionObject that can be invoked with \c Expr's
+ /// tag and children as expressions, as follows:
+ ///
+ /// \code
+ /// context(Expr::proto_tag(), arg_c\<0\>(expr), arg_c\<1\>(expr), ...)
+ /// \endcode
template<typename Expr, typename Context>
struct callable_eval<Expr, Context, N>
{
+ BOOST_PP_REPEAT(ARG_COUNT, BOOST_PROTO_ARG_N_TYPE, Expr)
+
typedef
typename boost::result_of<
Context(
typename Expr::proto_tag
- BOOST_PP_ENUM_TRAILING(ARG_COUNT, BOOST_PROTO_ARG_N_TYPE, Expr)
+ BOOST_PP_ENUM_PARAMS(ARG_COUNT, arg)
)
>::type
result_type;
+ /// \param expr The current expression
+ /// \param context The callable evaluation context
+ /// \return <tt>context(Expr::proto_tag(), arg_c\<0\>(expr), arg_c\<1\>(expr), ...)</tt>
result_type operator ()(Expr &expr, Context &context) const
{
return context(
Modified: trunk/boost/xpressive/proto/context/default.hpp
==============================================================================
--- trunk/boost/xpressive/proto/context/default.hpp (original)
+++ trunk/boost/xpressive/proto/context/default.hpp 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -220,6 +220,9 @@
BOOST_PROTO_BINARY_OP_RESULT(|=, proto::tag::bitwise_or_assign)
BOOST_PROTO_BINARY_OP_RESULT(^=, proto::tag::bitwise_xor_assign)
+ #undef BOOST_PROTO_UNARY_OP_RESULT
+ #undef BOOST_PROTO_BINARY_OP_RESULT
+
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::terminal, 0>
{
Modified: trunk/boost/xpressive/proto/ref.hpp
==============================================================================
--- trunk/boost/xpressive/proto/ref.hpp (original)
+++ trunk/boost/xpressive/proto/ref.hpp 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -59,7 +59,11 @@
BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_ARG, _)
- typename mpl::if_<is_const<Expr>, proto_base_expr const &, proto_base_expr &>::type
+ typename mpl::if_c<
+ is_const<Expr>::value
+ , proto_base_expr const &
+ , proto_base_expr &
+ >::type
proto_base() const
{
return this->expr.proto_base();
Modified: trunk/boost/xpressive/proto/transform/pass_through.hpp
==============================================================================
--- trunk/boost/xpressive/proto/transform/pass_through.hpp (original)
+++ trunk/boost/xpressive/proto/transform/pass_through.hpp 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -1,7 +1,10 @@
#ifndef BOOST_PP_IS_ITERATING
///////////////////////////////////////////////////////////////////////////////
/// \file pass_through.hpp
- /// TODO
+ ///
+ /// Definition of the pass_through transform, which is the default transform
+ /// of all of the expression generator metafunctions such as posit<>, plus<>
+ /// and nary_expr<>.
//
// Copyright 2008 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -14,7 +17,7 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
- #include <boost/mpl/if.hpp>
+ #include <boost/mpl/bool.hpp>
#include <boost/xpressive/proto/proto_fwd.hpp>
#include <boost/xpressive/proto/args.hpp>
#include <boost/xpressive/proto/detail/suffix.hpp>
@@ -75,8 +78,8 @@
///
/// \code
/// posit<
- /// T0::result<void(E0, S, V)>::::type
- /// , T1::result<void(E1, S, V)>::::type
+ /// T0::result<void(E0, S, V)>::type
+ /// , T1::result<void(E1, S, V)>::type
/// >::type
/// \endcode
///
@@ -113,9 +116,10 @@
/// , nary_expr<_, vararg<Promote> >
/// >
/// {};
- /// \code
+ /// \endcode
template<typename Grammar>
- struct pass_through : proto::callable
+ struct pass_through
+ : proto::callable
{
template<typename Sig>
struct result;
Modified: trunk/boost/xpressive/regex_compiler.hpp
==============================================================================
--- trunk/boost/xpressive/regex_compiler.hpp (original)
+++ trunk/boost/xpressive/regex_compiler.hpp 2008-02-27 13:48:22 EST (Wed, 27 Feb 2008)
@@ -320,19 +320,22 @@
negative = true; // fall-through
case token_positive_lookahead:
lookahead = true;
- seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+ //seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+ seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
break;
case token_negative_lookbehind:
negative = true; // fall-through
case token_positive_lookbehind:
lookbehind = true;
- seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+ //seq_end = detail::make_dynamic<BidiIter>(detail::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());
+ //seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
+ seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
break;
case token_comment:
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk