Update of /cvsroot/boost/boost/boost/xpressive
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23603/boost/xpressive

Modified Files:
        match_results.hpp regex_actions.hpp regex_compiler.hpp 
        regex_constants.hpp 
Log Message:
named captures for dynamic regexes, doxygen comments

Index: match_results.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/match_results.hpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- match_results.hpp   28 Apr 2007 01:42:16 -0000      1.17
+++ match_results.hpp   7 May 2007 04:41:25 -0000       1.18
@@ -17,6 +17,7 @@
 #endif
 
 #include <map>
+#include <vector>
 #include <utility>
 #include <iterator>
 #include <typeinfo>
@@ -32,6 +33,7 @@
 #endif
 #include <boost/xpressive/regex_constants.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
+#include <boost/xpressive/detail/core/regex_impl.hpp>
 #include <boost/xpressive/detail/core/sub_match_vector.hpp>
 #include <boost/xpressive/detail/utility/sequence_stack.hpp>
 #include <boost/xpressive/detail/core/results_cache.hpp>
@@ -258,6 +260,7 @@
       , extras_ptr_()
       , traits_()
       , args_()
+      , named_marks_()
     {
     }
 
@@ -281,6 +284,7 @@
       , extras_ptr_()
       , traits_()
       , args_(that.args_)
+      , named_marks_(that.named_marks_)
     {
         if(that)
         {
@@ -358,16 +362,10 @@
     /// matched marked sub-expression sub. If sub == 0 then returns a 
reference to a sub_match object
     /// representing the sequence that matched the whole regular expression.
     /// \pre sub \< (*this).size().
-    const_reference operator [](size_type sub) const
-    {
-        return this->sub_matches_[ sub ];
-    }
-
-    /// \overload
-    ///
-    const_reference operator [](detail::basic_mark_tag const &mark) const
+    template<typename Index>
+    const_reference operator [](Index const &index) const
     {
-        return this->sub_matches_[ detail::get_mark_number(mark) ];
+        return this->at_(index);
     }
 
     /// Returns a reference to the sub_match object representing the character 
sequence from
@@ -547,10 +545,12 @@
       , intrusive_ptr<detail::traits<char_type> const> const &traits
       , detail::sub_match_impl<BidiIter> *sub_matches
       , size_type size
+      , std::vector<detail::named_mark<char_type> > const &named_marks
     )
     {
         this->traits_ = traits;
         this->regex_id_ = regex_id;
+        this->named_marks_ = named_marks;
         
detail::core_access<BidiIter>::init_sub_match_vector(this->sub_matches_, 
sub_matches, size);
     }
 
@@ -611,6 +611,41 @@
 
     /// INTERNAL ONLY
     ///
+    const_reference at_(size_type sub) const
+    {
+        return this->sub_matches_[ sub ];
+    }
+
+    /// INTERNAL ONLY
+    ///
+    const_reference at_(detail::basic_mark_tag const &mark) const
+    {
+        return this->sub_matches_[ detail::get_mark_number(mark) ];
+    }
+
+    /// INTERNAL ONLY
+    ///
+    const_reference at_(char_type const *name) const
+    {
+        for(std::size_t i = 0; i < this->named_marks_.size(); ++i)
+        {
+            if(this->named_marks_[i].name_ == name)
+            {
+                return this->sub_matches_[ this->named_marks_[i].mark_nbr_ ];
+            }
+        }
+        throw regex_error(regex_constants::error_badmark, "invalid named 
back-reference");
+    }
+
+    /// INTERNAL ONLY
+    ///
+    const_reference at_(string_type const &name) const
+    {
+        return (*this)[name.c_str()];
+    }
+
+    /// INTERNAL ONLY
+    ///
     template<typename ForwardIterator, typename OutputIterator>
     OutputIterator format_ecma_262_(ForwardIterator cur, ForwardIterator end, 
OutputIterator out) const
     {
@@ -674,7 +709,14 @@
                 break;
 
             case BOOST_XPR_CHAR_(char_type, '\\'):
-                iout = this->format_escape_(++cur, end, iout);
+                if(++cur != end && BOOST_XPR_CHAR_(char_type, 'g') == *cur)
+                {
+                    iout = this->format_named_backref_(++cur, end, iout);
+                }
+                else
+                {
+                    iout = this->format_escape_(cur, end, iout);
+                }
                 break;
 
             default:
@@ -715,7 +757,14 @@
                 break;
 
             case BOOST_XPR_CHAR_(char_type, '\\'):
-                out = this->format_escape_(++cur, end, out);
+                if(++cur != end && BOOST_XPR_CHAR_(char_type, 'g') == *cur)
+                {
+                    out = this->format_named_backref_(++cur, end, out);
+                }
+                else
+                {
+                    out = this->format_escape_(cur, end, out);
+                }
                 break;
 
             case BOOST_XPR_CHAR_(char_type, '('):
@@ -953,6 +1002,38 @@
         return out;
     }
 
+    /// INTERNAL ONLY
+    ///
+    template<typename OutputIterator>
+    OutputIterator format_named_backref_
+    (
+        typename string_type::const_iterator &cur
+      , typename string_type::const_iterator end
+      , OutputIterator out
+    ) const
+    {
+        using namespace regex_constants;
+        detail::ensure(cur != end && BOOST_XPR_CHAR_(char_type, '<') == *cur++
+            , error_badmark, "invalid named back-reference");
+        typename string_type::const_iterator begin = cur;
+        for(; cur != end && BOOST_XPR_CHAR_(char_type, '>') != *cur; ++cur)
+        {}
+        detail::ensure(cur != begin && cur != end && 
BOOST_XPR_CHAR_(char_type, '>') == *cur
+            , error_badmark, "invalid named back-reference");
+
+        string_type name(begin, cur++);
+        for(std::size_t i = 0; i < this->named_marks_.size(); ++i)
+        {
+            if(this->named_marks_[i].name_ == name)
+            {
+                std::size_t sub = this->named_marks_[i].mark_nbr_;
+                return std::copy(this->sub_matches_[ sub ].first, 
this->sub_matches_[ sub ].second, out);
+            }
+        }
+
+        throw regex_error(error_badmark, "invalid named back-reference");
+    }
+
     regex_id_type regex_id_;
     detail::sub_match_vector<BidiIter> sub_matches_;
     BidiIter base_;
@@ -962,6 +1043,7 @@
     intrusive_ptr<extras_type> extras_ptr_;
     intrusive_ptr<detail::traits<char_type> const> traits_;
     detail::action_args_type args_;
+    std::vector<detail::named_mark<char_type> > named_marks_;
 };
 
 ///////////////////////////////////////////////////////////////////////////////

Index: regex_actions.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/regex_actions.hpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- regex_actions.hpp   1 May 2007 07:37:54 -0000       1.20
+++ regex_actions.hpp   7 May 2007 04:41:25 -0000       1.21
@@ -332,7 +332,8 @@
         struct insert
         {
             template<typename Sig, typename EnableIf = void>
-            struct result;
+            struct result
+            {};
 
             // assoc containers
             template<typename This, typename Cont, typename Value>
@@ -393,6 +394,8 @@
                 typedef Cont &type;
             };
 
+            /// operator()
+            ///
             template<typename Cont, typename A0>
             typename result<insert(Cont &, A0 &)>::type
             operator()(Cont &cont, A0 &a0) const
@@ -400,6 +403,8 @@
                 return cont.insert(a0);
             }
 
+            /// \overload
+            ///
             template<typename Cont, typename A0, typename A1>
             typename result<insert(Cont &, A0 &, A1 &)>::type
             operator()(Cont &cont, A0 &a0, A1 &a1) const
@@ -407,6 +412,8 @@
                 return cont.insert(a0, a1);
             }
 
+            /// \overload
+            ///
             template<typename Cont, typename A0, typename A1, typename A2>
             typename result<insert(Cont &, A0 &, A1 &, A2 &)>::type
             operator()(Cont &cont, A0 &a0, A1 &a1, A2 &a2) const

Index: regex_compiler.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/regex_compiler.hpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- regex_compiler.hpp  26 Apr 2007 16:38:01 -0000      1.14
+++ regex_compiler.hpp  7 May 2007 04:41:25 -0000       1.15
@@ -318,6 +318,37 @@
                 return 
detail::make_dynamic<BidiIter>(detail::regex_byref_matcher<BidiIter>(impl));
             }
 
+        case token_named_mark:
+            mark_nbr = static_cast<int>(++this->mark_count_);
+            for(std::size_t i = 0; i < this->self_->named_marks_.size(); ++i)
+            {
+                detail::ensure(this->self_->named_marks_[i].name_ != name, 
error_badmark, "named mark already exists");
+            }
+            
this->self_->named_marks_.push_back(detail::named_mark<char_type>(name, 
this->mark_count_));
+            seq = 
detail::make_dynamic<BidiIter>(detail::mark_begin_matcher(mark_nbr));
+            seq_end = 
detail::make_dynamic<BidiIter>(detail::mark_end_matcher(mark_nbr));
+            break;
+
+        case token_named_mark_ref:
+            detail::ensure
+            (
+                begin != end && token_group_end == 
this->traits_.get_token(begin, end)
+              , error_paren
+              , "mismatched parenthesis"
+            );
+            for(std::size_t i = 0; i < this->self_->named_marks_.size(); ++i)
+            {
+                if(this->self_->named_marks_[i].name_ == name)
+                {
+                    mark_nbr = 
static_cast<int>(this->self_->named_marks_[i].mark_nbr_);
+                    return detail::make_backref_xpression<BidiIter>
+                    (
+                        mark_nbr, this->traits_.flags(), this->rxtraits()
+                    );
+                }
+            }
+            throw regex_error(error_badmark, "invalid named back-reference");
+
         default:
             mark_nbr = static_cast<int>(++this->mark_count_);
             seq = 
detail::make_dynamic<BidiIter>(detail::mark_begin_matcher(mark_nbr));

Index: regex_constants.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/regex_constants.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- regex_constants.hpp 24 Mar 2007 10:07:29 -0000      1.8
+++ regex_constants.hpp 7 May 2007 04:41:25 -0000       1.9
@@ -221,6 +221,8 @@
                                 ///<
     error_badref,               ///< An nested regex is uninitialized.
                                 ///<
+    error_badmark,              ///< An invalid use of a named capture.
+                                ///<
     error_badlookbehind,        ///< An attempt to create a variable-width 
look-behind assertion
                                 ///< was detected.
                                 ///<


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

Reply via email to