|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53423 - trunk/libs/spirit/classic/doc
From: joel_at_[hidden]
Date: 2009-05-29 22:16:54
Author: djowel
Date: 2009-05-29 22:16:54 EDT (Fri, 29 May 2009)
New Revision: 53423
URL: http://svn.boost.org/trac/boost/changeset/53423
Log:
#3007
Text files modified:
trunk/libs/spirit/classic/doc/primitives.html | 131 +++++++++++++++------------------------
1 files changed, 52 insertions(+), 79 deletions(-)
Modified: trunk/libs/spirit/classic/doc/primitives.html
==============================================================================
--- trunk/libs/spirit/classic/doc/primitives.html (original)
+++ trunk/libs/spirit/classic/doc/primitives.html 2009-05-29 22:16:54 EDT (Fri, 29 May 2009)
@@ -1,30 +1,28 @@
-<html>
-<head>
-<title>Primitives</title>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<link rel="stylesheet" href="theme/style.css" type="text/css">
-</head>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+<title>Primitives</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link rel="stylesheet" href="theme/style.css" type="text/css"></head>
<body>
-<table width="100%" border="0" background="theme/bkd2.gif" cellspacing="2">
- <tr>
+<table background="theme/bkd2.gif" border="0" cellspacing="2" width="100%">
+ <tbody><tr>
<td width="10">
</td>
<td width="85%">
- <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Primitives</b></font>
+ <font face="Verdana, Arial, Helvetica, sans-serif" size="6"><b>Primitives</b></font>
</td>
- <td width="112"></td>
+ <td width="112"></td>
</tr>
-</table>
+</tbody></table>
<br>
<table border="0">
- <tr>
+ <tbody><tr>
<td width="10"></td>
<td width="30"></td>
<td width="30"></td>
<td width="30"></td>
</tr>
-</table>
+</tbody></table>
<p>The framework predefines some parser primitives. These are the most basic building
blocks that the client uses to build more complex parsers. These primitive parsers
are template classes, making them very flexible.</p>
@@ -39,17 +37,17 @@
the type of the character. This type typically corresponds to the input type,
usually <tt>char</tt> or <tt>wchar_t</tt>. The following expression creates
a temporary parser object which will recognize the single letter <span class="quotes">'X'</span>.</p>
-<pre><code><font color="#000000"><span class=identifier> </span><span class=identifier>chlit</span><span class=special><</span><span class=keyword>char</span><span class=special>>(</span><span class=literal>'X'</span><span class=special>);</span></font></code></pre>
+<pre><code><font color="#000000"><span class="identifier"> </span><span class="identifier">chlit</span><span class="special"><</span><span class="keyword">char</span><span class="special">>(</span><span class="literal">'X'</span><span class="special">);</span></font></code></pre>
<p>Using <tt>chlit</tt>'s generator function <tt>ch_p</tt> simplifies the usage
of the <tt>chlit<></tt> class (this is true of most Spirit parser classes
since most have corresponding generator functions). It is convenient to call
the function because the compiler will deduce the template type through argument
deduction for us. The example above could be expressed less verbosely using
the <tt>ch_p </tt>helper function. </p>
-<pre><code><font color="#000000"><span class=special> </span><span class=identifier>ch_p</span><span class=special>(</span><span class=literal>'X'</span><span class=special>) </span><span class=comment>// equivalent to chlit<char>('X') object</span></font></code></pre>
-<table width="80%" border="0" align="center">
- <tr>
- <td class="note_box"><img src="theme/lens.gif" width="15" height="16"> <b>Parser
+<pre><code><font color="#000000"><span class="special"> </span><span class="identifier">ch_p</span><span class="special">(</span><span class="literal">'X'</span><span class="special">) </span><span class="comment">// equivalent to chlit<char>('X') object</span></font></code></pre>
+<table align="center" border="0" width="80%">
+ <tbody><tr>
+ <td class="note_box"><img src="theme/lens.gif" height="16" width="15"> <b>Parser
generators</b><br>
<br>
Whenever you see an invocation of the parser generator function, it is equivalent
@@ -57,17 +55,9 @@
parser, even if, technically speaking, it is a function that generates a
character parser.</td>
</tr>
-</table>
+</tbody></table>
<p>The following grammar snippet shows these forms in action:</p>
-<pre><code><span class=comment> </span><span class=comment>// a rule can "store" a parser object. They're covered
- </span><span class=comment>// later, but for now just consider a rule as an opaque type
- </span><span class=identifier>rule</span><span class=special><> </span><span class=identifier>r1</span><span class=special>, </span><span class=identifier>r2</span><span class=special>, </span><span class=identifier>r3</span><span class=special>;
-
- </span><span class=identifier>chlit</span><span class=special><</span><span class=keyword>char</span><span class=special>> </span><span class=identifier>x</span><span class=special>(</span><span class=literal>'X'</span><span class=special>); </span><span class=comment>// declare a parser named x
-
- </span><span class=identifier>r1 </span><span class=special>= </span><span class=identifier>chlit</span><span class=special><</span><span class=keyword>char</span><span class=special>>(</span><span class=literal>'X'</span><span class=special>); </span><span class=comment>// explicit declaration
- </span><span class=identifier>r2 </span><span class=special>= </span><span class=identifier>x</span><span class=special>; </span><span class=comment>// using x
- </span><span class=identifier>r3 </span><span class=special>= </span><span class=identifier>ch_p</span><span class=special>(</span><span class=literal>'X'</span><span class=special>) </span><span class=comment>// using the generator</span></code></pre>
+<pre><code><span class="comment"> </span><span class="comment">// a rule can "store" a parser object. They're covered<br> </span><span class="comment">// later, but for now just consider a rule as an opaque type<br> </span><span class="identifier">rule</span><span class="special"><> </span><span class="identifier">r1</span><span class="special">, </span><span class="identifier">r2</span><span class="special">, </span><span class="identifier">r3</span><span class="special">;<br><br> </span><span class="identifier">chlit</span><span class="special"><</span><span class="keyword">char</span><span class="special">> </span><span class="identifier">x</span><span class="special">(</span><span class="literal">'X'</span><span class="special">); </span><span class="comment">// declare a parser named x<br><br> </span><span class="identifier">r1 </span><span class="special">= </span><span class="identifier">chlit</span><span class="special"><</span><span class="keyword">char</span><spa
n class="special">>(</span><span class="literal">'X'</span><span class="special">); </span><span class="comment">// explicit declaration<br> </span><span class="identifier">r2 </span><span class="special">= </span><span class="identifier">x</span><span class="special">; </span><span class="comment">// using x<br> </span><span class="identifier">r3 </span><span class="special">= </span><span class="identifier">ch_p</span><span class="special">(</span><span class="literal">'X'</span><span class="special">) </span><span class="comment">// using the generator</span></code></pre>
<h2> chlit and ch_p</h2>
<p>Matches a single character literal. <tt>chlit</tt> has a single template type
parameter which defaults to <tt>char</tt> (i.e. <tt>chlit<></tt> is equivalent
@@ -76,52 +66,41 @@
the template type parameters from the actual function arguments. The <tt>chlit</tt>
class constructor accepts a single parameter: the character it will match the
input against. Examples:</p>
-<pre><code><span class=comment> </span><span class=identifier>r1 </span><span class=special>= </span><span class=identifier>chlit</span><span class=special><>(</span><span class=literal>'X'</span><span class=special>);
- </span><span class=identifier>r2 </span><span class=special>= </span><span class=identifier>chlit</span><span class=special><</span><span class=keyword>wchar_t</span><span class=special>>(</span><span class=identifier>L</span><span class=literal>'X'</span><span class=special>);
- </span><span class=identifier>r3 </span><span class=special>= </span><span class=identifier>ch_p</span><span class=special>(</span><span class=literal>'X'</span><span class=special>);</span></code></pre>
+<pre><code><span class="comment"> </span><span class="identifier">r1 </span><span class="special">= </span><span class="identifier">chlit</span><span class="special"><>(</span><span class="literal">'X'</span><span class="special">);<br> </span><span class="identifier">r2 </span><span class="special">= </span><span class="identifier">chlit</span><span class="special"><</span><span class="keyword">wchar_t</span><span class="special">>(</span><span class="identifier">L</span><span class="literal">'X'</span><span class="special">);<br> </span><span class="identifier">r3 </span><span class="special">= </span><span class="identifier">ch_p</span><span class="special">(</span><span class="literal">'X'</span><span class="special">);</span></code></pre>
<p>Going back to our original example:</p>
-<pre><code><span class=special> </span><span class=identifier>group </span><span class=special>= </span><span class=literal>'(' </span><span class=special>>> </span><span class=identifier>expr </span><span class=special>>> </span><span class=literal>')'</span><span class=special>;
- </span><span class=identifier>expr1 </span><span class=special>= </span><span class=identifier>integer </span><span class=special>| </span><span class=identifier>group</span><span class=special>;
- </span><span class=identifier>expr2 </span><span class=special>= </span><span class=identifier>expr1 </span><span class=special>>> </span><span class=special>*((</span><span class=literal>'*' </span><span class=special>>> </span><span class=identifier>expr1</span><span class=special>) </span><span class=special>| </span><span class=special>(</span><span class=literal>'/' </span><span class=special>>> </span><span class=identifier>expr1</span><span class=special>));
- </span><span class=identifier>expr </span><span class=special>= </span><span class=identifier>expr2 </span><span class=special>>> </span><span class=special>*((</span><span class=literal>'+' </span><span class=special>>> </span><span class=identifier>expr2</span><span class=special>) </span><span class=special>| </span><span class=special>(</span><span class=literal>'-' </span><span class=special>>> </span><span class=identifier>expr2</span><span class=special>));</span></code></pre>
+<pre><code><span class="special"> </span><span class="identifier">group </span><span class="special">= </span><span class="literal">'(' </span><span class="special">>> </span><span class="identifier">expr </span><span class="special">>> </span><span class="literal">')'</span><span class="special">;<br> </span><span class="identifier">expr1 </span><span class="special">= </span><span class="identifier">integer </span><span class="special">| </span><span class="identifier">group</span><span class="special">;<br> </span><span class="identifier">expr2 </span><span class="special">= </span><span class="identifier">expr1 </span><span class="special">>> </span><span class="special">*((</span><span class="literal">'*' </span><span class="special">>> </span><span class="identifier">expr1</span><span class="special">) </span><span class="special">| </span><span class="special">(</span><span class="literal">'/' </span><span class="special">>> </span><span class="identifier">expr1
</span><span class="special">));<br> </span><span class="identifier">expr </span><span class="special">= </span><span class="identifier">expr2 </span><span class="special">>> </span><span class="special">*((</span><span class="literal">'+' </span><span class="special">>> </span><span class="identifier">expr2</span><span class="special">) </span><span class="special">| </span><span class="special">(</span><span class="literal">'-' </span><span class="special">>> </span><span class="identifier">expr2</span><span class="special">));</span></code></pre>
<p></p>
<p>the character literals <tt class="quotes">'('</tt>, <tt class="quotes">')'</tt>,
<tt class="quotes">'+'</tt>, <tt class="quotes">'-'</tt>, <tt class="quotes">'*'</tt>
and <tt class="quotes">'/'</tt> in the grammar declaration are <tt>chlit</tt>
objects that are implicitly created behind the scenes.</p>
-<table width="80%" border="0" align="center">
- <tr>
- <td class="note_box"><img src="theme/lens.gif" width="15" height="16"> <b>char
+<table align="center" border="0" width="80%">
+ <tbody><tr>
+ <td class="note_box"><img src="theme/lens.gif" height="16" width="15"> <b>char
operands</b> <br>
<br>
The reason this works is from two special templatized overloads of <tt>operator<span class="operators">>></span></tt>
that takes a (<tt>char</tt>, <tt> ParserT</tt>), or (<tt>ParserT</tt>, <tt>char</tt>).
These functions convert the character into a <tt>chlit</tt> object.</td>
</tr>
-</table>
+</tbody></table>
<p> One may prefer to declare these explicitly as:</p>
-<pre><code><span class=special> </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>plus</span><span class=special>(</span><span class=literal>'+'</span><span class=special>);
- </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>minus</span><span class=special>(</span><span class=literal>'-'</span><span class=special>);
- </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>times</span><span class=special>(</span><span class=literal>'*'</span><span class=special>);
- </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>divide</span><span class=special>(</span><span class=literal>'/'</span><span class=special>);
- </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>oppar</span><span class=special>(</span><span class=literal>'('</span><span class=special>);
- </span><span class=identifier>chlit</span><span class=special><> </span><span class=identifier>clpar</span><span class=special>(</span><span class=literal>')'</span><span class=special>);</span></code></pre>
+<pre><code><span class="special"> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">plus</span><span class="special">(</span><span class="literal">'+'</span><span class="special">);<br> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">minus</span><span class="special">(</span><span class="literal">'-'</span><span class="special">);<br> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">times</span><span class="special">(</span><span class="literal">'*'</span><span class="special">);<br> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">divide</span><span class="special">(</span><span class="literal">'/'</span><span class="special">);<br> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">oppar</span><span class="s
pecial">(</span><span class="literal">'('</span><span class="special">);<br> </span><span class="identifier">chlit</span><span class="special"><> </span><span class="identifier">clpar</span><span class="special">(</span><span class="literal">')'</span><span class="special">);</span></code></pre>
<h2>range and range_p</h2>
<p>A <tt>range</tt> of characters is created from a low/high character pair. Such
a parser matches a single character that is in the <tt>range</tt>, including
both endpoints. Like <tt>chlit</tt>, <tt>range</tt> has a single template type
parameter which defaults to <tt>char</tt>. The <tt>range</tt> class constructor
- accepts two parameters: the character range (<I>from</I> and <I>to</I>, inclusive)
+ accepts two parameters: the character range (<i>from</i> and <i>to</i>, inclusive)
it will match the input against. The function generator version is <tt>range_p</tt>.
Examples:</p>
-<pre><code><span class=special> </span><span class=identifier>range</span><span class=special><>(</span><span class=literal>'A'</span><span class=special>,</span><span class=literal>'Z'</span><span class=special>) </span><span class=comment>// matches 'A'..'Z'
- </span><span class=identifier>range_p</span><span class=special>(</span><span class=literal>'a'</span><span class=special>,</span><span class=literal>'z'</span><span class=special>) </span><span class=comment>// matches 'a'..'z'</span></code></pre>
-<p>Note, the first character must be "before" the second, according
+<pre><code><span class="special"> </span><span class="identifier">range</span><span class="special"><>(</span><span class="literal">'A'</span><span class="special">,</span><span class="literal">'Z'</span><span class="special">) </span><span class="comment">// matches 'A'..'Z'<br> </span><span class="identifier">range_p</span><span class="special">(</span><span class="literal">'a'</span><span class="special">,</span><span class="literal">'z'</span><span class="special">) </span><span class="comment">// matches 'a'..'z'</span></code></pre>
+<p>Note, the first character must be "before" the second, according
to the underlying character encoding characters. The range, like chlit is a
single character parser.</p>
-<table border="0" align="center" width="80%">
- <tr>
- <td class="note_box"><img src="theme/alert.gif" width="16" height="16"><b>
+<table align="center" border="0" width="80%">
+ <tbody><tr>
+ <td class="note_box"><img src="theme/alert.gif" height="16" width="16"><b>
Character mapping</b><br>
<br>
Character mapping to is inherently platform dependent. It is not guaranteed
@@ -129,7 +108,7 @@
we are well aware of the character set we are using such as ASCII, ISO-8859-1
or Unicode. Take care though when porting to another platform.</td>
</tr>
-</table>
+</tbody></table>
<h2> strlit and str_p</h2>
<p>This parser matches a string literal. <tt>strlit</tt> has a single template
type parameter: an iterator type. Internally, <tt>strlit</tt> holds a begin/end
@@ -140,14 +119,10 @@
This constructor may be used to build <tt>strlits</tt> from quoted string literals.
The second constructor takes in a first/last iterator pair. The function generator
version is <tt>str_p</tt>. Examples:</p>
-<pre><code><span class=comment> </span><span class=identifier>strlit</span><span class=special><>(</span><span class=string>"Hello World"</span><span class=special>)
- </span><span class=identifier>str_p</span><span class=special>(</span><span class=string>"Hello World"</span><span class=special>)
-
- </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 World"</span><span class=special>);
- </span><span class=identifier>strlit</span><span class=special><</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>::</span><span class=identifier>const_iterator</span><span class=special>>(</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>
-<table width="80%" border="0" align="center">
- <tr>
- <td class="note_box"><img src="theme/note.gif" width="16" height="16"> <b>Character
+<pre><code><span class="comment"> </span><span class="identifier">strlit</span><span class="special"><>(</span><span class="string">"Hello World"</span><span class="special">)<br> </span><span class="identifier">str_p</span><span class="special">(</span><span class="string">"Hello World"</span><span class="special">)<br><br> </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 World"</span><span class="special">);<br> </span><span class="identifier">strlit</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">const_iterator</span><span class="special">>(</span><span class="identifier">msg</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(), </span><s
pan class="identifier">msg</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span></code></pre>
+<table align="center" border="0" width="80%">
+ <tbody><tr>
+ <td class="note_box"><img src="theme/note.gif" height="16" width="16"> <b>Character
and phrase level parsing</b><br>
<br>
Typical parsers regard the processing of characters (symbols that form words
@@ -167,26 +142,23 @@
layers as needed. In theory, one may create a preprocessor, a lexical analyzer
and a parser proper, all using the same framework.</td>
</tr>
-</table>
+</tbody></table>
<h2>chseq and chseq_p</h2>
<p>Matches a character sequence. <tt>chseq</tt> has the same template type parameters
and constructor parameters as strlit. The function generator version is <tt>chseq_p</tt>.
Examples:</p>
-<pre><code><span class=special> </span><span class=identifier>chseq</span><span class=special><>(</span><span class=string>"ABCDEFG"</span><span class=special>)
- </span><span class=identifier>chseq_p</span><span class=special>(</span><span class=string>"ABCDEFG"</span><span class=special>)</span></code></pre>
+<pre><code><span class="special"> </span><span class="identifier">chseq</span><span class="special"><>(</span><span class="string">"ABCDEFG"</span><span class="special">)<br> </span><span class="identifier">chseq_p</span><span class="special">(</span><span class="string">"ABCDEFG"</span><span class="special">)</span></code></pre>
<p><tt>strlit</tt> is an implicit lexeme. That is, it works solely on the character
level. <tt>chseq</tt>, <tt>strlit</tt>'s twin, on the other hand, can work on
both the character and phrase levels. What this simply means is that it can
ignore white spaces in between the string characters. For example:</p>
-<pre><code><span class=special> </span><span class=identifier>chseq</span><span class=special><>(</span><span class=string>"ABCDEFG"</span><span class=special>)</span></code></pre>
+<pre><code><span class="special"> </span><span class="identifier">chseq</span><span class="special"><>(</span><span class="string">"ABCDEFG"</span><span class="special">)</span></code></pre>
<p>can parse:</p>
-<pre><span class=special> </span><span class=identifier>ABCDEFG
- </span><span class=identifier>A </span><span class=identifier>B </span><span class=identifier>C </span><span class=identifier>D </span><span class=identifier>E </span><span class=identifier>F </span><span class=identifier>G
- </span><span class=identifier>AB </span><span class=identifier>CD </span><span class=identifier>EFG</span></pre>
+<pre><span class="special"> </span><span class="identifier">ABCDEFG<br> </span><span class="identifier">A </span><span class="identifier">B </span><span class="identifier">C </span><span class="identifier">D </span><span class="identifier">E </span><span class="identifier">F </span><span class="identifier">G<br> </span><span class="identifier">AB </span><span class="identifier">CD </span><span class="identifier">EFG</span></pre>
<h2>More character parsers</h2>
<p>The framework also predefines the full repertoire of single character parsers:</p>
-<table width="90%" border="0" align="center">
- <tr>
+<table align="center" border="0" width="90%">
+ <tbody><tr>
<td class="table_title" colspan="2">Single character parsers</td>
</tr>
<tr>
@@ -242,11 +214,11 @@
<td class="table_cells" width="30%"><b>xdigit_p</b></td>
<td class="table_cells" width="70%">Matches hexadecimal digits</td>
</tr>
-</table>
+</tbody></table>
<h2><a name="negation"></a>negation ~</h2>
<p>Single character parsers such as the <tt>chlit</tt>, <tt>range</tt>, <tt>anychar_p</tt>,
<tt>alnum_p</tt> etc. can be negated. For example:</p>
-<pre><code><span class=special> ~</span><span class=identifier>ch_p</span><span class="special">(</span><span class="literal">'x'</span><span class="special">)</span></code></pre>
+<pre><code><span class="special"> ~</span><span class="identifier">ch_p</span><span class="special">(</span><span class="literal">'x'</span><span class="special">)</span></code></pre>
<p>matches any character except <tt>'x'</tt>. Double negation of a character parser
cancels out the negation. <tt>~~alpha_p</tt> is equivalent to <tt>alpha_p</tt>.</p>
<h2>eol_p</h2>
@@ -255,23 +227,24 @@
<p>Never matches anything and always fails.</p>
<h2>end_p</h2>
<p>Matches the end of input (returns a sucessful match with 0 length when the
- input is exhausted)</p>
+ input is exhausted)</p><h2>eps_p</h2>
+<p>The <strong>Epsilon</strong> (<tt>epsilon_p</tt> and <tt>eps_p</tt>) is a multi-purpose
+ parser that returns a zero length match. See Epsilon for details.</p><p></p>
<table border="0">
- <tr>
+ <tbody><tr>
<td width="10"></td>
<td width="30"></td>
<td width="30"></td>
<td width="30"></td>
</tr>
-</table>
+</tbody></table>
<br>
<hr size="1">
-<p class="copyright">Copyright © 1998-2003 Joel de Guzman<br>
- Copyright © 2003 Martin Wille<br>
+<p class="copyright">Copyright © 1998-2003 Joel de Guzman<br>
+ Copyright © 2003 Martin Wille<br>
<br>
<font size="2">Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt) </font> </p>
<p> </p>
-</body>
-</html>
+</body></html>
\ No newline at end of file
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