| [29] | 1 | <html> | 
|---|
 | 2 | <head> | 
|---|
 | 3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
 | 4 | <title>Chapter 21. Boost.Xpressive</title> | 
|---|
 | 5 | <link rel="stylesheet" href="boostbook.css" type="text/css"> | 
|---|
 | 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> | 
|---|
 | 7 | <link rel="start" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> | 
|---|
 | 8 | <link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)"> | 
|---|
 | 9 | <link rel="prev" href="variant/refs.html" title="References"> | 
|---|
 | 10 | <link rel="next" href="xpressive/user_s_guide.html" title="User's Guide"> | 
|---|
 | 11 | </head> | 
|---|
 | 12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> | 
|---|
 | 13 | <table cellpadding="2" width="100%"> | 
|---|
 | 14 | <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td> | 
|---|
 | 15 | <td align="center"><a href="../../index.htm">Home</a></td> | 
|---|
 | 16 | <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td> | 
|---|
 | 17 | <td align="center"><a href="../../people/people.htm">People</a></td> | 
|---|
 | 18 | <td align="center"><a href="../../more/faq.htm">FAQ</a></td> | 
|---|
 | 19 | <td align="center"><a href="../../more/index.htm">More</a></td> | 
|---|
 | 20 | </table> | 
|---|
 | 21 | <hr> | 
|---|
 | 22 | <div class="spirit-nav"> | 
|---|
 | 23 | <a accesskey="p" href="variant/refs.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="xpressive/user_s_guide.html"><img src="images/next.png" alt="Next"></a> | 
|---|
 | 24 | </div> | 
|---|
 | 25 | <div class="chapter" lang="en"> | 
|---|
 | 26 | <div class="titlepage"><div> | 
|---|
 | 27 | <div><h2 class="title"> | 
|---|
 | 28 | <a name="xpressive"></a>Chapter 21. Boost.Xpressive</h2></div> | 
|---|
 | 29 | <div><div class="author"><h3 class="author"> | 
|---|
 | 30 | <span class="firstname">Eric</span> <span class="surname">Niebler</span> | 
|---|
 | 31 | </h3></div></div> | 
|---|
 | 32 | <div><p class="copyright">Copyright © 2003, 2004 Eric Niebler</p></div> | 
|---|
 | 33 | <div><div class="legalnotice"> | 
|---|
 | 34 | <a name="id1953490"></a><p> | 
|---|
 | 35 |         Distributed under the Boost Software License, Version 1.0. (See accompanying | 
|---|
 | 36 |         file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) | 
|---|
 | 37 |       </p> | 
|---|
 | 38 | </div></div> | 
|---|
 | 39 | </div></div> | 
|---|
 | 40 | <div class="toc"> | 
|---|
 | 41 | <p><b>Table of Contents</b></p> | 
|---|
 | 42 | <dl> | 
|---|
 | 43 | <dt><span class="section"><a href="xpressive.html#boost_xpressive.preface">Preface</a></span></dt> | 
|---|
 | 44 | <dt><span class="section"><a href="xpressive/user_s_guide.html">User's Guide</a></span></dt> | 
|---|
 | 45 | <dd><dl> | 
|---|
 | 46 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.introduction">Introduction</a></span></dt> | 
|---|
 | 47 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.installing_xpressive">Installing xpressive</a></span></dt> | 
|---|
 | 48 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.quick_start">Quick Start</a></span></dt> | 
|---|
 | 49 | <dt><span class="section"><a href="xpressive/user_s_guide.html#xpressive.user_s_guide.creating_a_regex_object">Creating a Regex Object</a></span></dt> | 
|---|
 | 50 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.matching_and_searching">Matching and Searching</a></span></dt> | 
|---|
 | 51 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.accessing_results">Accessing Results</a></span></dt> | 
|---|
 | 52 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.string_substitutions">String Substitutions</a></span></dt> | 
|---|
 | 53 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.string_splitting_and_tokenization">String Splitting and Tokenization</a></span></dt> | 
|---|
 | 54 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.grammars_and_nested_matches">Grammars and Nested Matches</a></span></dt> | 
|---|
 | 55 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.localization_and_regex_traits">Localization and Regex Traits</a></span></dt> | 
|---|
 | 56 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.tips_n_tricks"> Tips 'N Tricks</a></span></dt> | 
|---|
 | 57 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.concepts">Concepts</a></span></dt> | 
|---|
 | 58 | <dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples">Examples</a></span></dt> | 
|---|
 | 59 | </dl></dd> | 
|---|
 | 60 | <dt><span class="section"><a href="xpressive/reference.html">Reference</a></span></dt> | 
|---|
 | 61 | <dd><dl> | 
|---|
 | 62 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.basic_regex.hpp">Header <boost/xpressive/basic_regex.hpp></a></span></dt> | 
|---|
 | 63 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.c_regex_traits.hpp">Header <boost/xpressive/traits/c_regex_traits.hpp></a></span></dt> | 
|---|
 | 64 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.cpp_regex_traits.hpp">Header <boost/xpressive/traits/cpp_regex_traits.hpp></a></span></dt> | 
|---|
 | 65 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.match_results.hpp">Header <boost/xpressive/match_results.hpp></a></span></dt> | 
|---|
 | 66 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.null_regex_traits.hpp">Header <boost/xpressive/traits/null_regex_traits.hpp></a></span></dt> | 
|---|
 | 67 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_algorithms.hpp">Header <boost/xpressive/regex_algorithms.hpp></a></span></dt> | 
|---|
 | 68 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_compiler.hpp">Header <boost/xpressive/regex_compiler.hpp></a></span></dt> | 
|---|
 | 69 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_constants.hpp">Header <boost/xpressive/regex_constants.hpp></a></span></dt> | 
|---|
 | 70 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_error.hpp">Header <boost/xpressive/regex_error.hpp></a></span></dt> | 
|---|
 | 71 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_iterator.hpp">Header <boost/xpressive/regex_iterator.hpp></a></span></dt> | 
|---|
 | 72 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_primitives.hpp">Header <boost/xpressive/regex_primitives.hpp></a></span></dt> | 
|---|
 | 73 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_token_iterator.hpp">Header <boost/xpressive/regex_token_iterator.hpp></a></span></dt> | 
|---|
 | 74 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_traits.hpp">Header <boost/xpressive/regex_traits.hpp></a></span></dt> | 
|---|
 | 75 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.sub_match.hpp">Header <boost/xpressive/sub_match.hpp></a></span></dt> | 
|---|
 | 76 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive.hpp">Header <boost/xpressive/xpressive.hpp></a></span></dt> | 
|---|
 | 77 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_dynamic.hpp">Header <boost/xpressive/xpressive_dynamic.hpp></a></span></dt> | 
|---|
 | 78 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_fwd.hpp">Header <boost/xpressive/xpressive_fwd.hpp></a></span></dt> | 
|---|
 | 79 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_static.hpp">Header <boost/xpressive/xpressive_static.hpp></a></span></dt> | 
|---|
 | 80 | <dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_typeof.hpp">Header <boost/xpressive/xpressive_typeof.hpp></a></span></dt> | 
|---|
 | 81 | </dl></dd> | 
|---|
 | 82 | <dt><span class="section"><a href="boost_xpressive/acknowledgments.html">Acknowledgments</a></span></dt> | 
|---|
 | 83 | <dt><span class="section"><a href="xpressive/appendices.html">Appendices</a></span></dt> | 
|---|
 | 84 | <dd><dl> | 
|---|
 | 85 | <dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.appendix_1__not_yet_implemented">Appendix 1: Not Yet Implemented</a></span></dt> | 
|---|
 | 86 | <dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.appendix_2__differences_from_boost_regex">Appendix 2: Differences from Boost.Regex</a></span></dt> | 
|---|
 | 87 | <dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.perf"> Appendix 3: Performance Comparison</a></span></dt> | 
|---|
 | 88 | </dl></dd> | 
|---|
 | 89 | </dl> | 
|---|
 | 90 | </div> | 
|---|
 | 91 | <div class="section" lang="en"> | 
|---|
 | 92 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> | 
|---|
 | 93 | <a name="boost_xpressive.preface"></a>Preface</h2></div></div></div> | 
|---|
 | 94 | <div class="blockquote"><blockquote class="blockquote"><p> | 
|---|
 | 95 |         <span class="emphasis"><em>Wife:</em></span> It's a floor wax!<br> <span class="emphasis"><em>Husband:</em></span> | 
|---|
 | 96 |         No, it's a dessert topping!<br> <span class="emphasis"><em>Announcer:</em></span> Stop! You're | 
|---|
 | 97 |         both right. It's a floor wax <span class="emphasis"><em>and</em></span> a dessert topping! | 
|---|
 | 98 |       </p></blockquote></div> | 
|---|
 | 99 | <div class="blockquote"><blockquote class="blockquote"><p> | 
|---|
 | 100 |         <span class="bold"><strong><span class="emphasis"><em>-- Saturday Night Live</em></span></strong></span> | 
|---|
 | 101 |       </p></blockquote></div> | 
|---|
 | 102 | <a name="boost_xpressive.preface.description"></a><h2> | 
|---|
 | 103 | <a name="id1953567"></a> | 
|---|
 | 104 |       Description | 
|---|
 | 105 |     </h2> | 
|---|
 | 106 | <p> | 
|---|
 | 107 |       xpressive is an advanced, object-oriented regular expression template library | 
|---|
 | 108 |       for C++. Regular expressions can be written as strings that are parsed at run-time, | 
|---|
 | 109 |       or as expression templates that are parsed at compile-time. Regular expressions | 
|---|
 | 110 |       can refer to each other and to themselves recursively, allowing you to build | 
|---|
 | 111 |       arbitrarily complicated grammars out of them. | 
|---|
 | 112 |     </p> | 
|---|
 | 113 | <a name="boost_xpressive.preface.motivation"></a><h2> | 
|---|
 | 114 | <a name="id1953590"></a> | 
|---|
 | 115 |       Motivation | 
|---|
 | 116 |     </h2> | 
|---|
 | 117 | <p> | 
|---|
 | 118 |       If you need to manipulate text in C++, you have typically had two disjoint | 
|---|
 | 119 |       options: a regular expression engine or a parser generator. Regular expression | 
|---|
 | 120 |       engines (like <a href="../../libs/regex" target="_top">Boost.Regex</a>) are powerful | 
|---|
 | 121 |       and flexible; patterns are represented as strings which can be specified at | 
|---|
 | 122 |       runtime. However, that means that syntax errors are likewise not detected until | 
|---|
 | 123 |       runtime. Also, regular expressions are ill-suited to advanced text processing | 
|---|
 | 124 |       tasks such as matching balanced, nested tags. Those tasks have traditionally | 
|---|
 | 125 |       been handled by parser generators (like the <a href="http://spirit.sourceforge.net" target="_top">Spirit | 
|---|
 | 126 |       Parser Framework</a>). These beasts are more powerful but less flexible. | 
|---|
 | 127 |       They generally don't allow you to arbitrarily modify your grammar rules on | 
|---|
 | 128 |       the fly. In addition, they don't have the exhaustive backtracking semantics | 
|---|
 | 129 |       of regular expressions, which can make it more challenging to author some types | 
|---|
 | 130 |       of patterns. | 
|---|
 | 131 |     </p> | 
|---|
 | 132 | <p> | 
|---|
 | 133 |       xpressive brings these two approaches seamlessly together and occupies a unique | 
|---|
 | 134 |       niche in the world of C++ text processing. With xpressive, you can choose to | 
|---|
 | 135 |       use it much as you would use <a href="../../libs/regex" target="_top">Boost.Regex</a>, | 
|---|
 | 136 |       representing regular expressions as strings. Or you can use it as you would | 
|---|
 | 137 |       use <a href="http://spirit.sourceforge.net" target="_top">Spirit</a>, writing your | 
|---|
 | 138 |       regexes as C++ expressions, enjoying all the benefits of an embedded language | 
|---|
 | 139 |       dedicated to text manipulation. What's more, you can mix the two to get the | 
|---|
 | 140 |       benefits of both, writing regular expression <span class="emphasis"><em>grammars</em></span> | 
|---|
 | 141 |       in which some of the regular expressions are statically bound -- hard-coded | 
|---|
 | 142 |       and syntax-checked by the compiler -- and others are dynamically bound and | 
|---|
 | 143 |       specified at runtime. These regular expressions can refer to each other recursively, | 
|---|
 | 144 |       matching patterns in strings that ordinary regular expressions cannot. | 
|---|
 | 145 |     </p> | 
|---|
 | 146 | <a name="boost_xpressive.preface.influences_and_related_work"></a><h2> | 
|---|
 | 147 | <a name="id1953666"></a> | 
|---|
 | 148 |       Influences and Related Work | 
|---|
 | 149 |     </h2> | 
|---|
 | 150 | <p> | 
|---|
 | 151 |       The design of xpressive's interface has been strongly influenced by John Maddock's | 
|---|
 | 152 |       <a href="../../libs/regex" target="_top">Boost.Regex</a> library and his <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1429.htm" target="_top">proposal</a> | 
|---|
 | 153 |       to add regular expressions to the Standard Library. I also drew a great deal | 
|---|
 | 154 |       of inspiration from Joel de Guzman's <a href="http://spirit.sourceforge.net" target="_top">Spirit | 
|---|
 | 155 |       Parser Framework</a>, which served as the model for static xpressive. Other | 
|---|
 | 156 |       sources of inspiration are the <a href="http://www.perl.com/pub/a/2002/06/04/apo5.html" target="_top">Perl | 
|---|
 | 157 |       6</a> redesign and <a href="http://research.microsoft.com/projects/greta" target="_top">GRETA</a>. | 
|---|
 | 158 |       (You can read a summary of the changes Perl 6 will bring to regex culture | 
|---|
 | 159 |       <a href="http://dev.perl.org/perl6/doc/design/syn/S05.html" target="_top">here</a>.) | 
|---|
 | 160 |     </p> | 
|---|
 | 161 | </div> | 
|---|
 | 162 | </div> | 
|---|
 | 163 | <table width="100%"><tr> | 
|---|
 | 164 | <td align="left"><small><p>Last revised: July 16, 2007 at 17:52:22 GMT</p></small></td> | 
|---|
 | 165 | <td align="right"><small></small></td> | 
|---|
 | 166 | </tr></table> | 
|---|
 | 167 | <hr> | 
|---|
 | 168 | <div class="spirit-nav"> | 
|---|
 | 169 | <a accesskey="p" href="variant/refs.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="xpressive/user_s_guide.html"><img src="images/next.png" alt="Next"></a> | 
|---|
 | 170 | </div> | 
|---|
 | 171 | </body> | 
|---|
 | 172 | </html> | 
|---|