Update of /cvsroot/boost/boost/boost/xpressive/detail/core/matcher
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv1249/detail/core/matcher
Modified Files:
action_matcher.hpp predicate_matcher.hpp
Log Message:
allow lambdas in custom assertions
Index: action_matcher.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/action_matcher.hpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- action_matcher.hpp 7 May 2007 04:41:25 -0000 1.20
+++ action_matcher.hpp 1 Jun 2007 06:19:00 -0000 1.21
@@ -36,6 +36,59 @@
namespace boost { namespace xpressive { namespace detail
{
+ #if BOOST_VERSION >= 103500
+
///////////////////////////////////////////////////////////////////////////////
+ // mem_ptr_eval
+ // Rewrites expressions of the form x->*foo(a) into foo(x, a) and then
+ // evaluates them.
+ template<typename Expr, typename Context>
+ struct mem_ptr_eval
+ {
+ typedef typename remove_reference<typename mpl::if_<
+ is_const<Expr>
+ , typename proto::result_of::right<Expr>::const_reference
+ , typename proto::result_of::right<Expr>::reference
+ >::type>::type right_type;
+
+ typedef typename remove_reference<typename mpl::if_<
+ is_const<Expr>
+ , typename proto::result_of::left<Expr>::const_reference
+ , typename proto::result_of::left<Expr>::reference
+ >::type>::type left_type;
+
+ typedef
+ typename proto::result_of::arg<
+ typename proto::result_of::arg_c<right_type, 0>::type
+ >::type
+ function_type;
+
+ typedef
+ fusion::transform_view<
+ typename fusion::result_of::push_front<
+ typename
fusion::result_of::pop_front<proto::children<right_type> >::type const
+ , reference_wrapper<left_type>
+ >::type const
+ , proto::eval_fun<Context>
+ >
+ evaluated_args;
+
+ typedef
+ typename fusion::result_of::invoke<function_type,
evaluated_args>::type
+ result_type;
+
+ result_type operator()(Expr &expr, Context &ctx) const
+ {
+ return fusion::invoke<function_type>(
+ proto::arg(proto::arg_c<0>(proto::right(expr)))
+ , evaluated_args(
+
fusion::push_front(fusion::pop_front(proto::children_of(proto::right(expr))),
boost::ref(proto::left(expr)))
+ , proto::eval_fun<Context>(ctx)
+ )
+ );
+ }
+ };
+ #endif
+
///////////////////////////////////////////////////////////////////////////////
// action_context
//
@@ -92,54 +145,12 @@
: eval_terminal<Expr>
{};
-#if BOOST_VERSION >= 103500
+ #if BOOST_VERSION >= 103500
template<typename Expr>
struct eval<Expr, proto::tag::mem_ptr>
- {
- typedef typename remove_reference<typename mpl::if_<
- is_const<Expr>
- , typename proto::result_of::right<Expr>::const_reference
- , typename proto::result_of::right<Expr>::reference
- >::type>::type right_type;
-
- typedef typename remove_reference<typename mpl::if_<
- is_const<Expr>
- , typename proto::result_of::left<Expr>::const_reference
- , typename proto::result_of::left<Expr>::reference
- >::type>::type left_type;
-
- typedef
- typename proto::result_of::arg<
- typename proto::result_of::arg_c<right_type, 0>::type
- >::type
- function_type;
-
- typedef
- fusion::transform_view<
- typename fusion::result_of::push_front<
- typename
fusion::result_of::pop_front<proto::children<right_type> >::type const
- , reference_wrapper<left_type>
- >::type const
- , proto::eval_fun<action_context const>
- >
- evaluated_args;
-
- typedef
- typename fusion::result_of::invoke<function_type,
evaluated_args>::type
- result_type;
-
- result_type operator()(Expr &expr, action_context const &ctx) const
- {
- return fusion::invoke<function_type>(
- proto::arg(proto::arg_c<0>(proto::right(expr)))
- , evaluated_args(
-
fusion::push_front(fusion::pop_front(proto::children_of(proto::right(expr))),
boost::ref(proto::left(expr)))
- , proto::eval_fun<action_context const>(ctx)
- )
- );
- }
- };
-#endif
+ : mem_ptr_eval<Expr, action_context const>
+ {};
+ #endif
private:
action_args_type *action_args_;
@@ -241,8 +252,8 @@
//
struct BindActionArgs
: proto::or_<
- subreg_transform<proto::terminal<detail::any_matcher> >
- , mark_transform<proto::terminal<detail::mark_placeholder> >
+ subreg_transform<proto::terminal<any_matcher> >
+ , mark_transform<proto::terminal<mark_placeholder> >
, by_ref_transform<proto::terminal<proto::_> >
, proto::nary_expr<proto::_, proto::vararg<BindActionArgs> >
>
Index: predicate_matcher.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/predicate_matcher.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- predicate_matcher.hpp 17 Apr 2007 05:02:36 -0000 1.2
+++ predicate_matcher.hpp 1 Jun 2007 06:19:00 -0000 1.3
@@ -13,12 +13,84 @@
# pragma once
#endif
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/placeholders.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/quant_style.hpp>
+#include <boost/xpressive/detail/core/matcher/action_matcher.hpp>
#include <boost/xpressive/detail/core/state.hpp>
+#include <boost/xpressive/proto/proto.hpp>
namespace boost { namespace xpressive { namespace detail
{
+
///////////////////////////////////////////////////////////////////////////////
+ // predicate_context
+ //
+ template<typename BidiIter>
+ struct predicate_context
+ {
+ explicit predicate_context(int sub, match_results<BidiIter> const
&what)
+ : sub_(sub)
+ , what_(what)
+ {}
+
+ // eval_terminal
+ template<typename Expr, typename Arg = typename
proto::result_of::arg<Expr>::type>
+ struct eval_terminal
+ : proto::default_eval<Expr, predicate_context const>
+ {};
+
+ template<typename Expr, typename Arg>
+ struct eval_terminal<Expr, reference_wrapper<Arg> >
+ {
+ typedef Arg &result_type;
+ result_type operator()(Expr &expr, predicate_context const &) const
+ {
+ return proto::arg(expr).get();
+ }
+ };
+
+ template<typename Expr>
+ struct eval_terminal<Expr, any_matcher>
+ {
+ typedef sub_match<BidiIter> const &result_type;
+ result_type operator()(Expr &expr, predicate_context const &ctx)
const
+ {
+ return ctx.what_[ctx.sub_];
+ }
+ };
+
+ template<typename Expr>
+ struct eval_terminal<Expr, mark_placeholder>
+ {
+ typedef sub_match<BidiIter> const &result_type;
+ result_type operator()(Expr &expr, predicate_context const &ctx)
const
+ {
+ return ctx.what_[expr];
+ }
+ };
+
+ // eval
+ template<typename Expr, typename Tag = typename Expr::tag_type>
+ struct eval
+ : proto::default_eval<Expr, predicate_context const>
+ {};
+
+ template<typename Expr>
+ struct eval<Expr, proto::tag::terminal>
+ : eval_terminal<Expr>
+ {};
+
+ #if BOOST_VERSION >= 103500
+ template<typename Expr>
+ struct eval<Expr, proto::tag::mem_ptr>
+ : mem_ptr_eval<Expr, predicate_context const>
+ {};
+ #endif
+
+ int sub_;
+ match_results<BidiIter> const &what_;
+ };
///////////////////////////////////////////////////////////////////////////////
// predicate_matcher
@@ -39,9 +111,24 @@
template<typename BidiIter, typename Next>
bool match(match_state<BidiIter> &state, Next const &next) const
{
+ typedef typename Predicate::arg0_type::predicate_type
predicate_type;
+ return this->match_(state, next, proto::is_expr<predicate_type>());
+ }
+
+ private:
+ template<typename BidiIter, typename Next>
+ bool match_(match_state<BidiIter> &state, Next const &next,
mpl::false_) const
+ {
sub_match<BidiIter> const &sub = state.sub_match(this->sub_);
return proto::arg(this->predicate_).pred(sub) && next.match(state);
}
+
+ template<typename BidiIter, typename Next>
+ bool match_(match_state<BidiIter> &state, Next const &next,
mpl::true_) const
+ {
+ predicate_context<BidiIter> ctx(this->sub_,
*state.context_.results_ptr_);
+ return proto::eval(proto::arg(this->predicate_).pred, ctx) &&
next.match(state);
+ }
};
}}}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs