|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57290 - in trunk: boost/xpressive libs/xpressive/doc
From: eric_at_[hidden]
Date: 2009-11-02 11:48:45
Author: eric_niebler
Date: 2009-11-02 11:48:44 EST (Mon, 02 Nov 2009)
New Revision: 57290
URL: http://svn.boost.org/trac/boost/changeset/57290
Log:
document xpressive::mark_tag
Text files modified:
trunk/boost/xpressive/regex_primitives.hpp | 97 ++++++++++++++++++++++++++++-----------
trunk/boost/xpressive/xpressive_fwd.hpp | 3
trunk/libs/xpressive/doc/Jamfile.v2 | 1
trunk/libs/xpressive/doc/static_regexes.qbk | 3 +
4 files changed, 73 insertions(+), 31 deletions(-)
Modified: trunk/boost/xpressive/regex_primitives.hpp
==============================================================================
--- trunk/boost/xpressive/regex_primitives.hpp (original)
+++ trunk/boost/xpressive/regex_primitives.hpp 2009-11-02 11:48:44 EST (Mon, 02 Nov 2009)
@@ -39,25 +39,6 @@
typedef assert_word_placeholder<word_begin> assert_word_begin;
typedef assert_word_placeholder<word_end> assert_word_end;
- struct mark_tag
- : proto::extends<basic_mark_tag, mark_tag>
- {
- mark_tag(int mark_nbr)
- {
- // Marks numbers must be integers greater than 0.
- BOOST_ASSERT(mark_nbr > 0);
- mark_placeholder mark = {mark_nbr};
- proto::value(*this) = mark;
- }
-
- operator basic_mark_tag const &() const
- {
- return this->proto_base();
- }
-
- using proto::extends<basic_mark_tag, mark_tag>::operator =;
- };
-
// workaround msvc-7.1 bug with function pointer types
// within function types:
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
@@ -531,8 +512,66 @@
detail::set_initializer_type const set = {{}};
///////////////////////////////////////////////////////////////////////////////
+/// \brief Sub-match placeholder type, used to create named captures in
+/// static regexes.
+///
+/// \c mark_tag is the type of the global sub-match placeholders \c s0, \c s1, etc.. You
+/// can use the \c mark_tag type to create your own sub-match placeholders with
+/// more meaningful names. This is roughly equivalent to the "named capture"
+/// feature of dynamic regular expressions.
+///
+/// To create a named sub-match placeholder, initialize it with a unique integer.
+/// The integer must only be unique within the regex in which the placeholder
+/// is used. Then you can use it within static regexes to created sub-matches
+/// by assigning a sub-expression to it, or to refer back to already created
+/// sub-matches.
+///
+/// \code
+/// mark_tag number(1); // "number" is now equivalent to "s1"
+/// // Match a number, followed by a space and the same number again
+/// sregex rx = (number = +_d) >> ' ' >> number;
+/// \endcode
+///
+/// After a successful \c regex_match() or \c regex_search(), the sub-match placeholder
+/// can be used to index into the <tt>match_results\<\></tt> object to retrieve the
+/// corresponding sub-match.
+struct mark_tag
+ : proto::extends<detail::basic_mark_tag, mark_tag>
+{
+ /// \brief Initialize a mark_tag placeholder
+ /// \param mark_nbr An integer that uniquely identifies this \c mark_tag
+ /// within the static regexes in which this \c mark_tag will be used.
+ /// \pre <tt>mark_nbr \> 0</tt>
+ mark_tag(int mark_nbr)
+ : proto::extends<detail::basic_mark_tag, mark_tag>(
+ detail::basic_mark_tag::make(mark_nbr)
+ )
+ {
+ // Marks numbers must be integers greater than 0.
+ BOOST_ASSERT(mark_nbr > 0);
+ }
+
+ /// INTERNAL ONLY
+ operator detail::basic_mark_tag const &() const
+ {
+ return this->proto_base();
+ }
+
+ using proto::extends<detail::basic_mark_tag, mark_tag>::operator =;
+};
+
+// This macro is used when declaring mark_tags that are global because
+// it guarantees that they are statically initialized. That avoids
+// order-of-initialization bugs. In user code, the simpler: mark_tag s0(0);
+// would be preferable.
+/// INTERNAL ONLY
+#define BOOST_XPRESSIVE_GLOBAL_MARK_TAG(NAME, VALUE) \
+ boost::xpressive::mark_tag::proto_base_expr const NAME = {{VALUE}} \
+ /**/
+
+///////////////////////////////////////////////////////////////////////////////
/// \brief Sub-match placeholder, like $& in Perl
-mark_tag::proto_base_expr const s0 = {{0}};
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s0, 0);
///////////////////////////////////////////////////////////////////////////////
/// \brief Sub-match placeholder, like $1 in perl.
@@ -546,15 +585,15 @@
/// After a successful regex_match() or regex_search(), the sub-match placeholders
/// can be used to index into the match_results\<\> object to retrieve the Nth
/// sub-match.
-mark_tag::proto_base_expr const s1 = {{1}};
-mark_tag::proto_base_expr const s2 = {{2}};
-mark_tag::proto_base_expr const s3 = {{3}};
-mark_tag::proto_base_expr const s4 = {{4}};
-mark_tag::proto_base_expr const s5 = {{5}};
-mark_tag::proto_base_expr const s6 = {{6}};
-mark_tag::proto_base_expr const s7 = {{7}};
-mark_tag::proto_base_expr const s8 = {{8}};
-mark_tag::proto_base_expr const s9 = {{9}};
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s1, 1);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s2, 2);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s3, 3);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s4, 4);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s5, 5);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s6, 6);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s7, 7);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s8, 8);
+BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s9, 9);
// NOTE: For the purpose of xpressive's documentation, make icase() look like an
// ordinary function. In reality, it is a function object defined in detail/icase.hpp
Modified: trunk/boost/xpressive/xpressive_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/xpressive_fwd.hpp (original)
+++ trunk/boost/xpressive/xpressive_fwd.hpp 2009-11-02 11:48:44 EST (Mon, 02 Nov 2009)
@@ -79,11 +79,10 @@
struct mark_placeholder;
typedef proto::terminal<mark_placeholder>::type basic_mark_tag;
- struct mark_tag;
} // namespace detail
- using detail::mark_tag;
+ struct mark_tag;
typedef void const *regex_id_type;
Modified: trunk/libs/xpressive/doc/Jamfile.v2
==============================================================================
--- trunk/libs/xpressive/doc/Jamfile.v2 (original)
+++ trunk/libs/xpressive/doc/Jamfile.v2 2009-11-02 11:48:44 EST (Mon, 02 Nov 2009)
@@ -13,6 +13,7 @@
<doxygen:param>EXTRACT_ALL=YES
<doxygen:param>"PREDEFINED=\"BOOST_XPRESSIVE_DOXYGEN_INVOKED\" \\
\"BOOST_DEDUCED_TYPENAME=typename\" \\
+ \"BOOST_XPRESSIVE_GLOBAL_MARK_TAG(x,y)=mark_tag const x(y)\" \\
\"BOOST_XPR_NONDEDUCED_TYPE_(X)=X\""
<doxygen:param>HIDE_UNDOC_MEMBERS=NO
<doxygen:param>EXTRACT_PRIVATE=NO
Modified: trunk/libs/xpressive/doc/static_regexes.qbk
==============================================================================
--- trunk/libs/xpressive/doc/static_regexes.qbk (original)
+++ trunk/libs/xpressive/doc/static_regexes.qbk 2009-11-02 11:48:44 EST (Mon, 02 Nov 2009)
@@ -169,6 +169,7 @@
[def _before_ [funcref boost::xpressive::before before]]
[def _after_ [funcref boost::xpressive::after after]]
[def _keep_ [funcref boost::xpressive::keep keep]]
+[def _mark_tag_ [classref boost::xpressive::mark_tag mark_tag]]
[table Perl syntax vs. Static xpressive syntax
[[Perl] [Static xpressive] [Meaning]]
@@ -224,6 +225,8 @@
[[[^(?!['stuff])]] [`~_before_(`[^['stuff]]`)`] [negative look-ahead assertion, match if not before ['stuff].]]
[[[^(?<=['stuff])]] [`_after_(`[^['stuff]]`)`] [positive look-behind assertion, match if after ['stuff] but don't include ['stuff] in the match. (['stuff] must be constant-width.)]]
[[[^(?<!['stuff])]] [`~_after_(`[^['stuff]]`)`] [negative look-behind assertion, match if not after ['stuff]. (['stuff] must be constant-width.)]]
+ [[[^(?P<['name]>['stuff])]] [`_mark_tag_ `[^['name]]`(`['n]`);`\n ...\n `(`[^['name]]`= `[^['stuff]]`)`] [Create a named capture.]]
+ [[[^(?P=['name])]] [`_mark_tag_ `[^['name]]`(`['n]`);`\n ...\n [^['name]]] [Refer back to a previously created named capture.]]
]
\n
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