Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-03-16 18:37:07


Author: eric_niebler
Date: 2008-03-16 18:37:06 EDT (Sun, 16 Mar 2008)
New Revision: 43660
URL: http://svn.boost.org/trac/boost/changeset/43660

Log:
allow lambdas to be used as formatters
Text files modified:
   trunk/boost/xpressive/detail/detail_fwd.hpp | 5 ++++
   trunk/boost/xpressive/match_results.hpp | 36 ++++++++++++++++++++++++-----
   trunk/boost/xpressive/regex_actions.hpp | 48 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 82 insertions(+), 7 deletions(-)

Modified: trunk/boost/xpressive/detail/detail_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/detail/detail_fwd.hpp (original)
+++ trunk/boost/xpressive/detail/detail_fwd.hpp 2008-03-16 18:37:06 EDT (Sun, 16 Mar 2008)
@@ -39,6 +39,11 @@
     struct type_info_less;
 
     typedef std::map<std::type_info const *, void *, type_info_less> action_args_type;
+
+ struct action_context;
+
+ template<typename BidiIter>
+ struct replacement_context;
 
     ///////////////////////////////////////////////////////////////////////////////
     // placeholders

Modified: trunk/boost/xpressive/match_results.hpp
==============================================================================
--- trunk/boost/xpressive/match_results.hpp (original)
+++ trunk/boost/xpressive/match_results.hpp 2008-03-16 18:37:06 EDT (Sun, 16 Mar 2008)
@@ -55,6 +55,8 @@
 #include <boost/xpressive/detail/utility/literals.hpp>
 #include <boost/xpressive/detail/utility/algorithm.hpp>
 #include <boost/xpressive/detail/utility/counted_base.hpp>
+#include <boost/xpressive/proto/proto_fwd.hpp>
+#include <boost/xpressive/proto/eval.hpp>
 
 namespace boost { namespace xpressive { namespace detail
 {
@@ -282,7 +284,7 @@
     operator Formatter *();
 };
 
-template<typename Formatter, typename What, typename Out>
+template<typename Formatter, typename What, typename Out, typename Void = void>
 struct formatter_arity
 {
     static formatter_wrapper<Formatter> &formatter;
@@ -301,6 +303,11 @@
     typedef mpl::size_t<value> type;
 };
 
+template<typename Formatter, typename What, typename Out>
+struct formatter_arity<Formatter, What, Out, typename Formatter::proto_is_expr_>
+ : mpl::size_t<4>
+{};
+
 template<typename T>
 struct is_char_ptr
   : mpl::false_
@@ -841,11 +848,11 @@
 
     /// INTERNAL ONLY
     ///
- template<typename OutputIterator, typename ForwardRange>
+ template<typename OutputIterator, typename Callable1>
     OutputIterator format_
     (
         OutputIterator out
- , ForwardRange const &format
+ , Callable1 const &format
       , regex_constants::match_flag_type
       , mpl::size_t<1>
     ) const
@@ -855,11 +862,11 @@
 
     /// INTERNAL ONLY
     ///
- template<typename OutputIterator, typename ForwardRange>
+ template<typename OutputIterator, typename Callable2>
     OutputIterator format_
     (
         OutputIterator out
- , ForwardRange const &format
+ , Callable2 const &format
       , regex_constants::match_flag_type
       , mpl::size_t<2>
     ) const
@@ -869,11 +876,11 @@
 
     /// INTERNAL ONLY
     ///
- template<typename OutputIterator, typename ForwardRange>
+ template<typename OutputIterator, typename Callable3>
     OutputIterator format_
     (
         OutputIterator out
- , ForwardRange const &format
+ , Callable3 const &format
       , regex_constants::match_flag_type flags
       , mpl::size_t<3>
     ) const
@@ -883,6 +890,21 @@
 
     /// INTERNAL ONLY
     ///
+ template<typename OutputIterator, typename Expr>
+ OutputIterator format_
+ (
+ OutputIterator out
+ , Expr const &format
+ , regex_constants::match_flag_type flags
+ , mpl::size_t<4>
+ ) const
+ {
+ detail::replacement_context<BidiIter> ctx(*this);
+ return this->format2_(out, proto::eval(format, ctx));
+ }
+
+ /// INTERNAL ONLY
+ ///
     template<typename ForwardIterator, typename OutputIterator>
     OutputIterator format_ecma_262_(ForwardIterator cur, ForwardIterator end, OutputIterator out) const
     {

Modified: trunk/boost/xpressive/regex_actions.hpp
==============================================================================
--- trunk/boost/xpressive/regex_actions.hpp (original)
+++ trunk/boost/xpressive/regex_actions.hpp 2008-03-16 18:37:06 EDT (Sun, 16 Mar 2008)
@@ -139,6 +139,54 @@
         {
             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)
+ {}
+
+ template<typename Sig>
+ struct result;
+
+ template<typename This>
+ struct result<This(proto::tag::terminal, mark_placeholder const &)>
+ {
+ typedef sub_match<BidiIter> const &type;
+ };
+
+ template<typename This>
+ struct result<This(proto::tag::terminal, any_matcher const &)>
+ {
+ typedef sub_match<BidiIter> const &type;
+ };
+
+ template<typename This, typename T>
+ struct result<This(proto::tag::terminal, reference_wrapper<T> const &)>
+ {
+ typedef T &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
+ {
+ return this->what_[0];
+ }
+
+ template<typename T>
+ T &operator ()(proto::tag::terminal, reference_wrapper<T> r) const
+ {
+ return r;
+ }
+ private:
+ match_results<BidiIter> const &what_;
+ };
     }
 
     namespace op


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