• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<title>Regular Expression Parser</title>
5<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6<link href="theme/style.css" rel="stylesheet" type="text/css">
7</head>
8
9<body>
10<table width="100%" border="0" background="theme/bkd2.gif" cellspacing="2">
11  <tr>
12    <td width="10" height="49"> <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>&nbsp;</b></font></td>
13    <td width="85%" height="49"> <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Regular Expression Parser</b></font></td>
14    <td width="112" height="49"><a href="http://spirit.sf.net"><img src="theme/spirit.gif" width="112" height="48" align="right" border="0"></a></td>
15  </tr>
16</table>
17<br>
18<table border="0">
19  <tr>
20    <td width="10"></td>
21    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
22    <td width="30"><a href="refactoring.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
23    <td width="30"><a href="scoped_lock.html"><img src="theme/r_arr.gif" border="0"></a></td>
24  </tr>
25</table>
26<p><a name="regular_expression_parser"></a>Regular expressions are a form of pattern-matching
27  that are often used in text processing. Many users will be familiar with the
28  usage of regular expressions. Initially there were the Unix utilities grep,
29  sed and awk, and the programming language perl, each of which make extensive
30  use of regular expressions. Today the usage of such regular expressions is integrated
31  in many more available systems.</p>
32<p>During parser construction it is often useful to have the power of regular
33  expressions available. The Regular Expression Parser was introduced, to make
34  the use of regular expressions accessible for Spirit parser construction.</p>
35<p>The Regular Expression Parser <tt>rxstrlit</tt> has a single template type
36  parameter: an iterator type. Internally, <tt>rxstrlit</tt> holds the Boost Regex
37  object containing the provided regular expression. The <tt>rxstrlit</tt> attempts
38  to match the current input stream with this regular expression. The template
39  type parameter defaults to <tt>char const<span class="operators">*</span></tt>.
40  <tt>rxstrlit</tt> has two constructors. The first accepts a null-terminated
41  character pointer. This constructor may be used to build <tt>rxstrlit's</tt>
42  from quoted regular expression literals. The second constructor takes in a first/last
43  iterator pair. The function generator version is <tt>regex_p</tt>. </p>
44<p>Here are some examples:</p>
45<pre><code><span class=comment>    </span><span class=identifier>rxstrlit</span><span class=special>&lt;&gt;(</span><span class=string>"Hello[[:space:]]+[W|w]orld"</span><span class=special>)
46    </span><span class=identifier>regex_p</span><span class=special>(</span><span class=string>"Hello[[:space:]]+[W|w]orld"</span><span class=special>)
47
48    </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>(</span><span class=string>"Hello[[:space:]]+[W|w]orld"</span><span class=special>);
49    rx</span><span class=identifier>strlit</span><span class=special>&lt;&gt;(</span><span class=identifier>msg</span><span class=special>.</span><span class=identifier>begin</span><span class=special>(), </span><span class=identifier>msg</span><span class=special>.</span><span class=identifier>end</span><span class=special>());</span></code></pre>
50<p>The generated parser object acts at the character level, thus an eventually
51  given skip parser is not used during the attempt to match the regular expression
52  (see <a href="faq.html#scanner_business">The Scanner Business</a>).</p>
53<p>The Regular Expression Parser is implemented by the help of the <a href="http://www.boost.org/libs/regex/index.html">Boost
54  Regex++ library</a>, so you have to have some limitations in mind. </p>
55<blockquote>
56  <p><img src="theme/bullet.gif" width="12" height="12"> Boost libraries have
57    to be installed on your computer and the Boost root directory has to be added
58    to your compiler <tt>#include&lt;...&gt;</tt> search path. You can download
59    the actual version at the <a href="http://www.boost.org/">Boost web site</a>.</p>
60  <p><img src="theme/bullet.gif" width="12" height="12"> The Boost Regex library
61    requires the usage of bi-directional iterators. So you have to ensure this
62    during the usage of the Spirit parser, which contains a Regular Expression
63    Parser.</p>
64  <p><img src="theme/bullet.gif" width="12" height="12"> The Boost Regex library
65    is not a header only library, as Spirit is, though it provides the possibility
66    to include all of the sources, if you are using it in one compilation unit
67    only. Define the preprocessor constant <tt>BOOST_SPIRIT_NO_REGEX_LIB</tt> before
68    including the spirit Regular Expression Parser header, if you want to include
69    all the Boost Regex sources into this compilation unit. If you are using the
70    Regular Expression Parser in more than one compilation unit, you should not
71    define this constant and must link your application against the regex library
72    as described in the related documentation.</p>
73</blockquote>
74<p> <img src="theme/lens.gif" width="15" height="16"> See <a href="../example/fundamental/regular_expression.cpp">regular_expression.cpp</a> for a compilable example. This is part of the Spirit distribution.</p>
75<table border="0">
76  <tr>
77    <td width="10"></td>
78    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
79    <td width="30"><a href="refactoring.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
80    <td width="30"><a href="scoped_lock.html"><img src="theme/r_arr.gif" border="0"></a></td>
81  </tr>
82</table>
83<br>
84<hr size="1">
85<p class="copyright">Copyright &copy; 2001-2002 Hartmut Kaiser<br>
86  <br>
87  <font size="2">Use, modification and distribution is subject to the Boost Software
88    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
89    http://www.boost.org/LICENSE_1_0.txt)</font></p>
90</body>
91</html>
92