Boost logo

Boost-Commit :

From: joel_at_[hidden]
Date: 2008-07-13 02:49:43


Author: djowel
Date: 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
New Revision: 47381
URL: http://svn.boost.org/trac/boost/changeset/47381

Log:
added context to the what function
Added:
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/mini_xml___error_handling.html (contents, props changed)
   trunk/libs/spirit/example/qi/mini_xml3.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/doc/html/index.html | 8
   trunk/libs/spirit/doc/html/spirit/__lex__.html | 4
   trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_1___a_word_counter_using___lex__.html | 10
   trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_2___a_better_word_counter_using___lex__.html | 6
   trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_3___counting_words_using_a_parser.html | 8
   trunk/libs/spirit/doc/html/spirit/__lex__/abstracts.html | 6
   trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/lexer_states.html | 6
   trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/the__static__lexer_model.html | 4
   trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/tokenizing_input_data.html | 4
   trunk/libs/spirit/doc/html/spirit/__lex__/reference/lexer_class.html | 8
   trunk/libs/spirit/doc/html/spirit/acknowledgments.html | 2
   trunk/libs/spirit/doc/html/spirit/qi_and_karma.html | 404 ++++++++++++++++++++++++++++++++++++++-
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts.html | 4
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/debugging.html | 8
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parse_trees_and_asts.html | 8
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing.html | 10
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing_and_generating.html | 10
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/quick_reference.html | 2
   trunk/libs/spirit/doc/html/spirit/qi_and_karma/reference.html | 10
   trunk/libs/spirit/doc/qi_and_karma.qbk | 1
   trunk/libs/spirit/doc/qi_and_karma/error_handling.qbk | 113 +++++++++++
   trunk/libs/spirit/doc/qi_and_karma/mini_xml.qbk | 23 +
   trunk/libs/spirit/example/qi/mini_xml1.cpp | 1
   trunk/libs/spirit/example/qi/mini_xml2.cpp | 1
   24 files changed, 583 insertions(+), 78 deletions(-)

Modified: trunk/libs/spirit/doc/html/index.html
==============================================================================
--- trunk/libs/spirit/doc/html/index.html (original)
+++ trunk/libs/spirit/doc/html/index.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -72,6 +72,8 @@
         - Parsing into structs</a></span></dt>
 <dt><span class="section"><a href="spirit/qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_">Mini
         XML - ASTs!</a></span></dt>
+<dt><span class="section"><a href="spirit/qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling">Mini
+ XML - Error Handling</a></span></dt>
 </dl></dd>
 <dt><span class="section">Abstracts</span></dt>
 <dd><dl>
@@ -89,8 +91,8 @@
 <dt><span class="section">Rules</span></dt>
 <dt><span class="section">Grammars</span></dt>
 <dt><span class="section">Debugging</span></dt>
-<dt><span class="section"><a href="spirit/qi_and_karma/abstracts/error_handling.html">Error
- Handling</a></span></dt>
+<dt><span class="section"><a href="spirit/qi_and_karma/abstracts/mini_xml___error_handling.html">Mini
+ XML - Error Handling</a></span></dt>
 <dt><span class="section"><a href="spirit/qi_and_karma/abstracts/parse_trees_and_asts.html">Parse
         Trees and ASTs</a></span></dt>
 </dl></dd>
@@ -512,7 +514,7 @@
 </div>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: July 12, 2008 at 11:03:36 GMT</small></p></td>
+<td align="left"><p><small>Last revised: July 13, 2008 at 06:03:25 GMT</small></p></td>
 <td align="right"><div class="copyright-footer"></div></td>
 </tr></table>
 <hr>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -100,7 +100,7 @@
         </li>
 </ul></div>
 <a name="spirit.__lex__.introduction_to___lex__.why_using_a_separate_lexer"></a><h4>
-<a name="id481510"></a>
+<a name="id487196"></a>
         <a href="__lex__.html#spirit.__lex__.introduction_to___lex__.why_using_a_separate_lexer">Why
         Using a Separate Lexer</a>
       </h4>
@@ -200,7 +200,7 @@
         grammar recognizers.
       </p>
 <a name="spirit.__lex__.introduction_to___lex__.advantages_of_using__emphasis_spirit_lex__emphasis_"></a><h4>
-<a name="id481863"></a>
+<a name="id487571"></a>
         <a href="__lex__.html#spirit.__lex__.introduction_to___lex__.advantages_of_using__emphasis_spirit_lex__emphasis_">Advantages
         of using <span class="emphasis"><em>Spirit.Lex</em></span></a>
       </h4>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_1___a_word_counter_using___lex__.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_1___a_word_counter_using___lex__.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_1___a_word_counter_using___lex__.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -43,7 +43,7 @@
           (for the full example code see here: word_count_functor.cpp).
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.prerequisites"></a><h5>
-<a name="id482373"></a>
+<a name="id488083"></a>
           <a href="quickstart_1___a_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.prerequisites">Prerequisites</a>
         </h5>
 <p>
@@ -85,7 +85,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.defining_tokens"></a><h5>
-<a name="id482762"></a>
+<a name="id488473"></a>
           <a href="quickstart_1___a_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.defining_tokens">Defining
           Tokens</a>
         </h5>
@@ -142,7 +142,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.doing_the_useful_work"></a><h5>
-<a name="id483274"></a>
+<a name="id488985"></a>
           <a href="quickstart_1___a_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.doing_the_useful_work">Doing
           the Useful Work</a>
         </h5>
@@ -208,7 +208,7 @@
           as well.
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.pulling_everything_together"></a><h5>
-<a name="id483979"></a>
+<a name="id489689"></a>
           <a href="quickstart_1___a_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.pulling_everything_together">Pulling
           Everything Together</a>
         </h5>
@@ -264,7 +264,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.comparing__emphasis_spirit_lex__emphasis__with__ulink_url__http___flex_sourceforge_net___flex__ulink_"></a><h5>
-<a name="id485121"></a>
+<a name="id490831"></a>
           <a href="quickstart_1___a_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_1___a_word_counter_using___lex__.comparing__emphasis_spirit_lex__emphasis__with__ulink_url__http___flex_sourceforge_net___flex__ulink_">Comparing
           <span class="emphasis"><em>Spirit.Lex</em></span> with Flex</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_2___a_better_word_counter_using___lex__.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_2___a_better_word_counter_using___lex__.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_2___a_better_word_counter_using___lex__.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -45,7 +45,7 @@
           options along the lines (for the full example code see here: word_count_lexer.cpp).
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.prerequisites"></a><h5>
-<a name="id486195"></a>
+<a name="id491905"></a>
           <a href="quickstart_2___a_better_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.prerequisites">Prerequisites</a>
         </h5>
 <p>
@@ -123,7 +123,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.semantic_actions_in__emphasis_spirit_lex__emphasis_"></a><h5>
-<a name="id487152"></a>
+<a name="id492861"></a>
           <a href="quickstart_2___a_better_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.semantic_actions_in__emphasis_spirit_lex__emphasis_">Semantic
           Actions in <span class="emphasis"><em>Spirit.Lex</em></span></a>
         </h5>
@@ -240,7 +240,7 @@
           to the internal lexer context.
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.associating_token_definitions_with_the_lexer"></a><h5>
-<a name="id488613"></a>
+<a name="id494322"></a>
           <a href="quickstart_2___a_better_word_counter_using___lex__.html#spirit.__lex__.__lex___tutorials.quickstart_2___a_better_word_counter_using___lex__.associating_token_definitions_with_the_lexer">Associating
           Token Definitions with the Lexer</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_3___counting_words_using_a_parser.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_3___counting_words_using_a_parser.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/__lex___tutorials/quickstart_3___counting_words_using_a_parser.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -70,7 +70,7 @@
           code see here: word_count.cpp).
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.prerequisites"></a><h5>
-<a name="id489203"></a>
+<a name="id494904"></a>
           <a href="quickstart_3___counting_words_using_a_parser.html#spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.prerequisites">Prerequisites</a>
         </h5>
 <p>
@@ -121,7 +121,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.defining_tokens"></a><h5>
-<a name="id489770"></a>
+<a name="id495471"></a>
           <a href="quickstart_3___counting_words_using_a_parser.html#spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.defining_tokens">Defining
           Tokens</a>
         </h5>
@@ -177,7 +177,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.using_token_definition_instances_as_parsers"></a><h5>
-<a name="id490278"></a>
+<a name="id495979"></a>
           <a href="quickstart_3___counting_words_using_a_parser.html#spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.using_token_definition_instances_as_parsers">Using
           Token Definition Instances as Parsers</a>
         </h5>
@@ -355,7 +355,7 @@
           </p></td></tr>
 </table></div>
 <a name="spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.pulling_everything_together"></a><h5>
-<a name="id491666"></a>
+<a name="id497372"></a>
           <a href="quickstart_3___counting_words_using_a_parser.html#spirit.__lex__.__lex___tutorials.quickstart_3___counting_words_using_a_parser.pulling_everything_together">Pulling
           Everything Together</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/abstracts.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/abstracts.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/abstracts.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -84,7 +84,7 @@
             of the <span class="emphasis"><em>Spirit.Lex</em></span> library.
           </p>
 <a name="spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.the_anatomy_of_a_token"></a><h6>
-<a name="id493147"></a>
+<a name="id498853"></a>
             <a href="abstracts.html#spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.the_anatomy_of_a_token">The
             Anatomy of a Token</a>
           </h6>
@@ -222,7 +222,7 @@
             when it is requested for the first time.
           </p>
 <a name="spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.the_physiognomy_of_a_token_definition"></a><h6>
-<a name="id493952"></a>
+<a name="id499658"></a>
             <a href="abstracts.html#spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.the_physiognomy_of_a_token_definition">The
             Physiognomy of a Token Definition</a>
           </h6>
@@ -296,7 +296,7 @@
 </td></tr>
 </table></div>
 <a name="spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.examples_of_using__link_linkend__spirit___lex___reference_token_class___code__phrase_role__identifier__lexertl_token__phrase__phrase_role__special___lt__gt___phrase___code___link_"></a><h6>
-<a name="id494366"></a>
+<a name="id500072"></a>
             <a href="abstracts.html#spirit.__lex__.abstracts.lexer_primitives.about_tokens_and_token_values.examples_of_using__link_linkend__spirit___lex___reference_token_class___code__phrase_role__identifier__lexertl_token__phrase__phrase_role__special___lt__gt___phrase___code___link_">Examples
             of using lexertl_token<></a>
           </h6>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/lexer_states.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/lexer_states.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/lexer_states.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -26,17 +26,17 @@
 <div class="titlepage"><div><div><h4 class="title">
 <a name="spirit.__lex__.abstracts.lexer_states"></a>Lexer States</h4></div></div></div>
 <a name="spirit.__lex__.abstracts.lexer_states.controlling_the_lexer_state_from_lexer_semantic_actions"></a><h5>
-<a name="id498718"></a>
+<a name="id504425"></a>
           <a href="lexer_states.html#spirit.__lex__.abstracts.lexer_states.controlling_the_lexer_state_from_lexer_semantic_actions">Controlling
           the Lexer State from Lexer Semantic Actions</a>
         </h5>
 <a name="spirit.__lex__.abstracts.lexer_states.controlling_the_lexer_state_from_parser_semantic_actions"></a><h5>
-<a name="id498749"></a>
+<a name="id504455"></a>
           <a href="lexer_states.html#spirit.__lex__.abstracts.lexer_states.controlling_the_lexer_state_from_parser_semantic_actions">Controlling
           the Lexer State from Parser Semantic Actions</a>
         </h5>
 <a name="spirit.__lex__.abstracts.lexer_states.using_a_lexer_state_for_the_skip_parser"></a><h5>
-<a name="id498780"></a>
+<a name="id504486"></a>
           <a href="lexer_states.html#spirit.__lex__.abstracts.lexer_states.using_a_lexer_state_for_the_skip_parser">Using
           a Lexer State for the Skip Parser</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/the__static__lexer_model.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/the__static__lexer_model.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/the__static__lexer_model.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -181,7 +181,7 @@
 <p>
         </p>
 <a name="spirit.__lex__.abstracts.the__static__lexer_model.generating_the_static_analyzer"></a><h5>
-<a name="id496757"></a>
+<a name="id502464"></a>
           <a href="the__static__lexer_model.html#spirit.__lex__.abstracts.the__static__lexer_model.generating_the_static_analyzer">Generating
           the Static Analyzer</a>
         </h5>
@@ -228,7 +228,7 @@
           the next topic (the full generated code can be viewed here).
         </p>
 <a name="spirit.__lex__.abstracts.the__static__lexer_model.modifying_the_dynamic_analyzer"></a><h5>
-<a name="id497282"></a>
+<a name="id502988"></a>
           <a href="the__static__lexer_model.html#spirit.__lex__.abstracts.the__static__lexer_model.modifying_the_dynamic_analyzer">Modifying
           the Dynamic Analyzer</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/tokenizing_input_data.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/tokenizing_input_data.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/abstracts/tokenizing_input_data.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -30,12 +30,12 @@
         Input Data">Tokenizing
         Input Data</a></h4></div></div></div>
 <a name="spirit.__lex__.abstracts.tokenizing_input_data.the_tokenize___function"></a><h5>
-<a name="id495173"></a>
+<a name="id500879"></a>
           <a href="tokenizing_input_data.html#spirit.__lex__.abstracts.tokenizing_input_data.the_tokenize___function">The
           tokenize() function</a>
         </h5>
 <a name="spirit.__lex__.abstracts.tokenizing_input_data.the_generate_static___function"></a><h5>
-<a name="id495201"></a>
+<a name="id500908"></a>
           <a href="tokenizing_input_data.html#spirit.__lex__.abstracts.tokenizing_input_data.the_generate_static___function">The
           generate_static() function</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/__lex__/reference/lexer_class.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/__lex__/reference/lexer_class.html (original)
+++ trunk/libs/spirit/doc/html/spirit/__lex__/reference/lexer_class.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -26,22 +26,22 @@
 <div class="titlepage"><div><div><h4 class="title">
 <a name="spirit.__lex__.reference.lexer_class"></a>Lexer Class</h4></div></div></div>
 <a name="spirit.__lex__.reference.lexer_class.the_lexertl_lexer_class_implementing_the_dynamic_model"></a><h5>
-<a name="id498971"></a>
+<a name="id504678"></a>
           <a href="lexer_class.html#spirit.__lex__.reference.lexer_class.the_lexertl_lexer_class_implementing_the_dynamic_model">The
           lexertl_lexer Class Implementing the Dynamic Model</a>
         </h5>
 <a name="spirit.__lex__.reference.lexer_class.the_lexertl_actor_lexer_class_implementing_the_dynamic_model"></a><h5>
-<a name="id498999"></a>
+<a name="id504706"></a>
           <a href="lexer_class.html#spirit.__lex__.reference.lexer_class.the_lexertl_actor_lexer_class_implementing_the_dynamic_model">The
           lexertl_actor_lexer Class Implementing the Dynamic Model</a>
         </h5>
 <a name="spirit.__lex__.reference.lexer_class.the_lexertl_static_lexer_class_implementing_the_static_model"></a><h5>
-<a name="id499030"></a>
+<a name="id504737"></a>
           <a href="lexer_class.html#spirit.__lex__.reference.lexer_class.the_lexertl_static_lexer_class_implementing_the_static_model">The
           lexertl_static_lexer Class Implementing the Static Model</a>
         </h5>
 <a name="spirit.__lex__.reference.lexer_class.the_lexertl_static_actor_lexer_class_implementing_the_static_model"></a><h5>
-<a name="id499059"></a>
+<a name="id504766"></a>
           <a href="lexer_class.html#spirit.__lex__.reference.lexer_class.the_lexertl_static_actor_lexer_class_implementing_the_static_model">The
           lexertl_static_actor_lexer Class Implementing the Static Model</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/acknowledgments.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/acknowledgments.html (original)
+++ trunk/libs/spirit/doc/html/spirit/acknowledgments.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -46,7 +46,7 @@
       <span class="bold"><b>FIXME</b></span>: Add more people
     </p>
 <a name="spirit.acknowledgments.acknowledgements_from_the_spirit_v1__emphasis_classic__emphasis__documentation"></a><h3>
-<a name="id500076"></a>
+<a name="id505783"></a>
       <a href="acknowledgments.html#spirit.acknowledgments.acknowledgements_from_the_spirit_v1__emphasis_classic__emphasis__documentation">Acknowledgements
       from the Spirit V1 <span class="emphasis"><em>classic</em></span> Documentation</a>
     </h3>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -48,6 +48,8 @@
         - Parsing into structs</a></span></dt>
 <dt><span class="section"><a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_">Mini
         XML - ASTs!</a></span></dt>
+<dt><span class="section"><a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling">Mini
+ XML - Error Handling</a></span></dt>
 </dl></dd>
 <dt><span class="section">Abstracts</span></dt>
 <dd><dl>
@@ -65,8 +67,8 @@
 <dt><span class="section">Rules</span></dt>
 <dt><span class="section">Grammars</span></dt>
 <dt><span class="section">Debugging</span></dt>
-<dt><span class="section"><a href="qi_and_karma/abstracts/error_handling.html">Error
- Handling</a></span></dt>
+<dt><span class="section"><a href="qi_and_karma/abstracts/mini_xml___error_handling.html">Mini
+ XML - Error Handling</a></span></dt>
 <dt><span class="section"><a href="qi_and_karma/abstracts/parse_trees_and_asts.html">Parse
         Trees and ASTs</a></span></dt>
 </dl></dd>
@@ -111,6 +113,8 @@
         - Parsing into structs</a></span></dt>
 <dt><span class="section"><a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_">Mini
         XML - ASTs!</a></span></dt>
+<dt><span class="section"><a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling">Mini
+ XML - Error Handling</a></span></dt>
 </dl></div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
@@ -2008,13 +2012,20 @@
 <li>
             Local Variables
           </li>
+<li>
+ Not Predicate
+ </li>
 </ul></div>
 <p>
           The full cpp files for these examples can be found here: ../../example/qi/mini_xml1.cpp
           and here: ../../example/qi/mini_xml2.cpp
         </p>
+<p>
+ There are a couple of sample toy-xml files in: ../../example/qi/mini_xml_samples
+ for testing purposes. "4.toyxml" has an error in it.
+ </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.first_cut"></a><h5>
-<a name="id474121"></a>
+<a name="id474137"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.first_cut">First
           Cut</a>
         </h5>
@@ -2037,6 +2048,7 @@
 
         <span class="identifier">start_tag</span> <span class="special">=</span>
                 <span class="char">'&lt;'</span>
+ <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
             <span class="special">&gt;&gt;</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&gt;'</span><span class="special">)</span> <span class="special">[</span><span class="identifier">_val</span> <span class="special">+=</span> <span class="identifier">_1</span><span class="special">]]</span>
             <span class="special">&gt;&gt;</span> <span class="char">'&gt;'</span>
         <span class="special">;</span>
@@ -2084,7 +2096,7 @@
           by the placeholder <tt class="computeroutput"><span class="identifier">_val</span></tt>).
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.alternates"></a><h5>
-<a name="id475380"></a>
+<a name="id475429"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.alternates">Alternates</a>
         </h5>
 <pre class="programlisting">
@@ -2112,17 +2124,42 @@
 <pre class="programlisting">
 <span class="identifier">start_tag</span> <span class="special">=</span>
         <span class="char">'&lt;'</span>
+ <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
     <span class="special">&gt;&gt;</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&gt;'</span><span class="special">)</span> <span class="special">[</span><span class="identifier">_val</span> <span class="special">+=</span> <span class="identifier">_1</span><span class="special">]]</span>
     <span class="special">&gt;&gt;</span> <span class="char">'&gt;'</span>
 <span class="special">;</span>
 </pre>
+<a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.not_predicate"></a><h5>
+<a name="id475897"></a>
+ <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.not_predicate">Not
+ Predicate</a>
+ </h5>
 <p>
- Nothing special. Almost the same as the <tt class="computeroutput"><span class="identifier">text</span></tt>
- rule apart from the added <tt class="computeroutput"><span class="char">'&lt;'</span></tt>
- and <tt class="computeroutput"><span class="char">'&gt;'</span></tt>.
+ <tt class="computeroutput"><span class="identifier">start_tag</span></tt> is similar to
+ the <tt class="computeroutput"><span class="identifier">text</span></tt> rule apart from
+ the added <tt class="computeroutput"><span class="char">'&lt;'</span></tt> and <tt class="computeroutput"><span class="char">'&gt;'</span></tt>. But wait, to make sure that the <tt class="computeroutput"><span class="identifier">start_tag</span></tt> does not parse <tt class="computeroutput"><span class="identifier">end_tag</span></tt>s too, we add: <tt class="computeroutput"><span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span></tt>. This
+ is a "Not Predicate":
+ </p>
+<pre class="programlisting">
+<span class="special">!</span><span class="identifier">p</span>
+</pre>
+<p>
+ It will try the parser, <tt class="computeroutput"><span class="identifier">p</span></tt>.
+ If it is successful, fail, otherwise, pass. In other words, it negates
+ the result of <tt class="computeroutput"><span class="identifier">p</span></tt>. Like the
+ <tt class="computeroutput"><span class="identifier">eps</span></tt>, it does not consume
+ any input though. It will always rewind the iterator position to where
+ it was upon entry. So, the expression:
+ </p>
+<pre class="programlisting">
+<span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
+</pre>
+<p>
+ basically says: we should not have a <tt class="computeroutput"><span class="char">'/'</span></tt>
+ at this point.
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.inherited_attribute"></a><h5>
-<a name="id475860"></a>
+<a name="id476145"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.inherited_attribute">Inherited
           Attribute</a>
         </h5>
@@ -2150,7 +2187,7 @@
           <tt class="computeroutput"><span class="identifier">_r3</span></tt>, etc. if you have more).
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.a_lazy_lit"></a><h5>
-<a name="id476142"></a>
+<a name="id476429"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.a_lazy_lit">A
           Lazy Lit</a>
         </h5>
@@ -2186,7 +2223,7 @@
           accessors, provided by Phoenix.
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.how_it_all_works"></a><h5>
-<a name="id476625"></a>
+<a name="id476912"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.how_it_all_works">How
           it all works</a>
         </h5>
@@ -2235,7 +2272,7 @@
           as <tt class="computeroutput"><span class="identifier">_r1</span></tt>.
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.the_structures"></a><h5>
-<a name="id477074"></a>
+<a name="id477360"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.the_structures">The
           Structures</a>
         </h5>
@@ -2269,7 +2306,7 @@
 <p>
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.of_alternates_and_variants"></a><h5>
-<a name="id477348"></a>
+<a name="id477635"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.of_alternates_and_variants">Of
           Alternates and Variants</a>
         </h5>
@@ -2298,7 +2335,7 @@
           of <tt class="computeroutput"><span class="identifier">a</span></tt> and <tt class="computeroutput"><span class="identifier">B</span></tt> is the attribute of <tt class="computeroutput"><span class="identifier">b</span></tt>.
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.adapting_structs_again"></a><h5>
-<a name="id477620"></a>
+<a name="id477907"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.adapting_structs_again">Adapting
           structs again</a>
         </h5>
@@ -2325,7 +2362,7 @@
 <p>
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.one_more_take"></a><h5>
-<a name="id477802"></a>
+<a name="id478089"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.one_more_take">One
           More Take</a>
         </h5>
@@ -2352,6 +2389,7 @@
 
         <span class="identifier">start_tag</span> <span class="special">%=</span>
                 <span class="char">'&lt;'</span>
+ <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
             <span class="special">&gt;&gt;</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&gt;'</span><span class="special">)]</span>
             <span class="special">&gt;&gt;</span> <span class="char">'&gt;'</span>
         <span class="special">;</span>
@@ -2388,7 +2426,7 @@
           in the <tt class="computeroutput"><span class="identifier">xml</span></tt> rule:
         </p>
 <a name="spirit.qi_and_karma.tutorials.mini_xml___asts_.local_variables"></a><h5>
-<a name="id478738"></a>
+<a name="id479056"></a>
           <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___asts_.local_variables">Local
           Variables</a>
         </h5>
@@ -2414,7 +2452,7 @@
             the parsed start-tag string is placed in the local variable specified
             by (yet another) Phoenix
             placeholder: <tt class="computeroutput"><span class="identifier">_a</span></tt>. We have
- only one local variable. If we had more, these are designated by <tt class="computeroutput"><span class="identifier">_b</span></tt>..<tt class="computeroutput"><span class="identifier">z</span></tt>.
+ only one local variable. If we had more, these are designated by <tt class="computeroutput"><span class="identifier">_b</span></tt>..<tt class="computeroutput"><span class="identifier">_z</span></tt>.
           </li>
 <li>
             Then we parse zero or more <tt class="computeroutput"><span class="identifier">node</span></tt>s.
@@ -2430,6 +2468,340 @@
           attribute. It's all taken cared of thatnks to the auto-rule.
         </p>
 </div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="spirit.qi_and_karma.tutorials.mini_xml___error_handling"></a><a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling" title="Mini
+ XML - Error Handling">Mini
+ XML - Error Handling</a></h4></div></div></div>
+<p>
+ A parser will not be complete without error handling. Spirit2 provides
+ some facilities to make it easy to adapt a grammar for error handling.
+ We'll wrap up the Qi tutorial with another version of the mini xml parser,
+ this time, with error handling.
+ </p>
+<p>
+ ../../example/qi/mini_xml1.cpp
+ and here: ../../example/qi/mini_xml2.cpp
+ </p>
+<p>
+ Here's the grammar:
+ </p>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting">
+<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">&gt;</span>
+<span class="keyword">struct</span> <span class="identifier">mini_xml_grammar</span>
+ <span class="special">:</span> <span class="identifier">grammar</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml</span><span class="special">(),</span> <span class="identifier">locals</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;,</span> <span class="identifier">space_type</span><span class="special">&gt;</span>
+<span class="special">{</span>
+ <span class="identifier">mini_xml_grammar</span><span class="special">()</span>
+ <span class="special">:</span> <span class="identifier">mini_xml_grammar</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">xml</span><span class="special">,</span> <span class="string">"xml"</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="identifier">text</span> <span class="special">%=</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&lt;'</span><span class="special">)];</span>
+ <span class="identifier">node</span> <span class="special">%=</span> <span class="identifier">xml</span> <span class="special">|</span> <span class="identifier">text</span><span class="special">;</span>
+
+ <span class="identifier">start_tag</span> <span class="special">%=</span>
+ <span class="char">'&lt;'</span>
+ <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&gt;'</span><span class="special">)]</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+ <span class="special">;</span>
+
+ <span class="identifier">end_tag</span> <span class="special">=</span>
+ <span class="string">"&lt;/"</span>
+ <span class="special">&gt;</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">_r1</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+ <span class="special">;</span>
+
+ <span class="identifier">xml</span> <span class="special">%=</span>
+ <span class="identifier">start_tag</span><span class="special">[</span><span class="identifier">_a</span> <span class="special">=</span> <span class="identifier">_1</span><span class="special">]</span>
+ <span class="special">&gt;</span> <span class="special">*</span><span class="identifier">node</span>
+ <span class="special">&gt;</span> <span class="identifier">end_tag</span><span class="special">(</span><span class="identifier">_a</span><span class="special">)</span>
+ <span class="special">;</span>
+
+ <span class="identifier">xml</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"xml"</span><span class="special">);</span>
+ <span class="identifier">node</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"node"</span><span class="special">);</span>
+ <span class="identifier">text</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"text"</span><span class="special">);</span>
+ <span class="identifier">start_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"start_tag"</span><span class="special">);</span>
+ <span class="identifier">end_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"end_tag"</span><span class="special">);</span>
+
+ <span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">fail</span><span class="special">&gt;</span>
+ <span class="special">(</span>
+ <span class="identifier">xml</span>
+ <span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"Error! Expecting "</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">_4</span> <span class="comment">// what failed?
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">" here: \""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">construct</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">)</span> <span class="comment">// iterators to error-pos, end
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"\""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
+ <span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml</span><span class="special">(),</span> <span class="identifier">locals</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;,</span> <span class="identifier">space_type</span><span class="special">&gt;</span> <span class="identifier">xml</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml_node</span><span class="special">(),</span> <span class="identifier">space_type</span><span class="special">&gt;</span> <span class="identifier">node</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</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">space_type</span><span class="special">&gt;</span> <span class="identifier">text</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</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">space_type</span><span class="special">&gt;</span> <span class="identifier">start_tag</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">void</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">space_type</span><span class="special">&gt;</span> <span class="identifier">end_tag</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+ </p>
+<p>
+ What's new?
+ </p>
+<a name="spirit.qi_and_karma.tutorials.mini_xml___error_handling.readable_names"></a><h5>
+<a name="id480845"></a>
+ <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling.readable_names">Readable
+ Names</a>
+ </h5>
+<p>
+ First, when we call the base class, we give the grammar a name:
+ </p>
+<pre class="programlisting">
+<span class="special">:</span> <span class="identifier">mini_xml_grammar</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">xml</span><span class="special">,</span> <span class="string">"xml"</span><span class="special">)</span>
+</pre>
+<p>
+ Then, we name all our rules:
+ </p>
+<pre class="programlisting">
+<span class="identifier">xml</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"xml"</span><span class="special">);</span>
+<span class="identifier">node</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"node"</span><span class="special">);</span>
+<span class="identifier">text</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"text"</span><span class="special">);</span>
+<span class="identifier">start_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"start_tag"</span><span class="special">);</span>
+<span class="identifier">end_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"end_tag"</span><span class="special">);</span>
+</pre>
+<a name="spirit.qi_and_karma.tutorials.mini_xml___error_handling.on_error"></a><h5>
+<a name="id481100"></a>
+ <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling.on_error">On
+ Error</a>
+ </h5>
+<p>
+ <tt class="computeroutput"><span class="identifier">on_error</span></tt> declares our error
+ handler:
+ </p>
+<pre class="programlisting">
+<span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">Action</span><span class="special">&gt;(</span><span class="identifier">rule</span><span class="special">,</span> <span class="identifier">handler</span><span class="special">)</span>
+</pre>
+<p>
+ This will specify what we will do when we get an error. We will print out
+ an error message using phoenix:
+ </p>
+<pre class="programlisting">
+<span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">fail</span><span class="special">&gt;</span>
+<span class="special">(</span>
+ <span class="identifier">xml</span>
+ <span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"Error! Expecting "</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">_4</span> <span class="comment">// what failed?
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">" here: \""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">construct</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">)</span> <span class="comment">// iterators to error-pos, end
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"\""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
+<span class="special">);</span>
+</pre>
+<p>
+ we choose to <tt class="computeroutput"><span class="identifier">fail</span></tt> in our
+ example for the <tt class="computeroutput"><span class="identifier">Action</span></tt>:
+ Quit and fail. Return a no_match (false). It can be one of:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ <tt class="computeroutput"><span class="identifier">Action</span></tt>
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ fail
+ </p>
+ </td>
+<td>
+ <p>
+ Quit and fail. Return a no_match.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ retry
+ </p>
+ </td>
+<td>
+ <p>
+ Attempt error recovery, possibly moving the iterator position.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ accept
+ </p>
+ </td>
+<td>
+ <p>
+ Force success, moving the iterator position appropriately.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ rethrow
+ </p>
+ </td>
+<td>
+ <p>
+ Rethrows the error.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+<p>
+ <tt class="computeroutput"><span class="identifier">rule</span></tt> is the rule we attach
+ the handler to. In our case, we are attaching to the <tt class="computeroutput"><span class="identifier">xml</span></tt>
+ rule.
+ </p>
+<p>
+ <tt class="computeroutput"><span class="identifier">handler</span></tt> is the actual error
+ handling function. It expects 4 arguments:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Arg
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ first
+ </p>
+ </td>
+<td>
+ <p>
+ The position of the iterator when the rule with the handler was
+ entered.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ last
+ </p>
+ </td>
+<td>
+ <p>
+ The end of input.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ error-pos
+ </p>
+ </td>
+<td>
+ <p>
+ The actual position of the iterator where the error occurred.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ what
+ </p>
+ </td>
+<td>
+ <p>
+ What failed: a string decribing the failure.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+<a name="spirit.qi_and_karma.tutorials.mini_xml___error_handling.expectation_points"></a><h5>
+<a name="id481774"></a>
+ <a href="qi_and_karma.html#spirit.qi_and_karma.tutorials.mini_xml___error_handling.expectation_points">Expectation
+ Points</a>
+ </h5>
+<p>
+ You might not have noticed it, but some of our expressions changed from
+ using the <tt class="computeroutput"><span class="special">&gt;&gt;</span></tt> to <tt class="computeroutput"><span class="special">&gt;</span></tt>. Look, for example:
+ </p>
+<pre class="programlisting">
+<span class="identifier">end_tag</span> <span class="special">=</span>
+ <span class="string">"&lt;/"</span>
+ <span class="special">&gt;</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">_r1</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+<span class="special">;</span>
+</pre>
+<p>
+ What is it? It's the <span class="emphasis"><em>expectation</em></span> operator. You will
+ have some "deterministic points" in the grammar. Those are the
+ places where backtracking <span class="bold"><b>cannot</b></span> occur.
+ For our example above, when you get a <tt class="computeroutput"><span class="string">"&lt;/"</span></tt>,
+ you definitely must see a valid end-tag label next. It should be the one
+ you got from the start-tag. After that, you definitely must have a <tt class="computeroutput"><span class="char">'&gt;'</span></tt> next. Otherwise, there is no point in
+ proceeding forward and trying other branches, regardless where they are.
+ The input is definitely erroneous. When this happens, an expectation_failure
+ exception is thrown. Somewhere outward, the error handler will catch the
+ exception.
+ </p>
+<p>
+ Try building the parser: ../../example/qi/mini_xml2.cpp.
+ You can find some examples in: ../../example/qi/mini_xml_samples
+ for testing purposes. "4.toyxml" has an error in it:
+ </p>
+<pre class="programlisting">
+<span class="special">&lt;</span><span class="identifier">foo</span><span class="special">&gt;&lt;</span><span class="identifier">bar</span><span class="special">&gt;&lt;/</span><span class="identifier">foo</span><span class="special">&gt;&lt;/</span><span class="identifier">bar</span><span class="special">&gt;</span>
+</pre>
+<p>
+ Running the example with this gives you:
+ </p>
+<pre class="programlisting">
+<span class="identifier">Error</span><span class="special">!</span> <span class="identifier">Expecting</span> <span class="string">"bar"</span> <span class="identifier">here</span><span class="special">:</span> <span class="string">"foo&gt;&lt;/bar&gt;"</span>
+<span class="identifier">Error</span><span class="special">!</span> <span class="identifier">Expecting</span> <span class="identifier">end_tag</span> <span class="identifier">here</span><span class="special">:</span> <span class="string">"&lt;bar&gt;&lt;/foo&gt;&lt;/bar&gt;"</span>
+<span class="special">-------------------------</span>
+<span class="identifier">Parsing</span> <span class="identifier">failed</span>
+<span class="special">-------------------------</span>
+</pre>
+</div>
 </div>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -40,8 +40,8 @@
 <dt><span class="section">Rules</span></dt>
 <dt><span class="section">Grammars</span></dt>
 <dt><span class="section">Debugging</span></dt>
-<dt><span class="section"><a href="abstracts/error_handling.html">Error
- Handling</a></span></dt>
+<dt><span class="section"><a href="abstracts/mini_xml___error_handling.html">Mini
+ XML - Error Handling</a></span></dt>
 <dt><span class="section"><a href="abstracts/parse_trees_and_asts.html">Parse
         Trees and ASTs</a></span></dt>
 </dl></div>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/debugging.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/debugging.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/debugging.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -7,8 +7,8 @@
 <link rel="start" href="../../../index.html" title="Spirit 2.0">
 <link rel="up" href="../abstracts.html" title="Abstracts">
 <link rel="prev" href="grammars.html" title="Grammars">
-<link rel="next" href="error_handling.html" title="Error
- Handling">
+<link rel="next" href="mini_xml___error_handling.html" title="Mini
+ XML - Error Handling">
 </head>
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 <table cellpadding="2" width="100%"><tr>
@@ -21,7 +21,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="grammars.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="error_handling.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="grammars.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="mini_xml___error_handling.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 <div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title">
 <a name="spirit.qi_and_karma.abstracts.debugging"></a>Debugging</h4></div></div></div></div>
@@ -36,7 +36,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="grammars.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="error_handling.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="grammars.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="mini_xml___error_handling.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 </body>
 </html>

Added: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/mini_xml___error_handling.html
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/mini_xml___error_handling.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -0,0 +1,375 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Mini
+ XML - Error Handling</title>
+<link rel="stylesheet" href="../../../../../../../doc/html/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
+<link rel="start" href="../../../index.html" title="Spirit 2.0">
+<link rel="up" href="../abstracts.html" title="Abstracts">
+<link rel="prev" href="debugging.html" title="Debugging">
+<link rel="next" href="parse_trees_and_asts.html" title="Parse
+ Trees and ASTs">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="debugging.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="parse_trees_and_asts.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="spirit.qi_and_karma.abstracts.mini_xml___error_handling"></a><a href="mini_xml___error_handling.html" title="Mini
+ XML - Error Handling">Mini
+ XML - Error Handling</a></h4></div></div></div>
+<p>
+ A parser will not be complete without error handling. Spirit2 provides
+ some facilities to make it easy to adapt a grammar for error handling.
+ We'll wrap up the Qi tutorial with another version of the mini xml parser,
+ this time, with error handling.
+ </p>
+<p>
+ ../../example/qi/mini_xml1.cpp
+ and here: ../../example/qi/mini_xml2.cpp
+ </p>
+<p>
+ Here's the grammar:
+ </p>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting">
+<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">&gt;</span>
+<span class="keyword">struct</span> <span class="identifier">mini_xml_grammar</span>
+ <span class="special">:</span> <span class="identifier">grammar</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml</span><span class="special">(),</span> <span class="identifier">locals</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;,</span> <span class="identifier">space_type</span><span class="special">&gt;</span>
+<span class="special">{</span>
+ <span class="identifier">mini_xml_grammar</span><span class="special">()</span>
+ <span class="special">:</span> <span class="identifier">mini_xml_grammar</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">xml</span><span class="special">,</span> <span class="string">"xml"</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="identifier">text</span> <span class="special">%=</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&lt;'</span><span class="special">)];</span>
+ <span class="identifier">node</span> <span class="special">%=</span> <span class="identifier">xml</span> <span class="special">|</span> <span class="identifier">text</span><span class="special">;</span>
+
+ <span class="identifier">start_tag</span> <span class="special">%=</span>
+ <span class="char">'&lt;'</span>
+ <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'/'</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="identifier">lexeme</span><span class="special">[+(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">'&gt;'</span><span class="special">)]</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+ <span class="special">;</span>
+
+ <span class="identifier">end_tag</span> <span class="special">=</span>
+ <span class="string">"&lt;/"</span>
+ <span class="special">&gt;</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">_r1</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+ <span class="special">;</span>
+
+ <span class="identifier">xml</span> <span class="special">%=</span>
+ <span class="identifier">start_tag</span><span class="special">[</span><span class="identifier">_a</span> <span class="special">=</span> <span class="identifier">_1</span><span class="special">]</span>
+ <span class="special">&gt;</span> <span class="special">*</span><span class="identifier">node</span>
+ <span class="special">&gt;</span> <span class="identifier">end_tag</span><span class="special">(</span><span class="identifier">_a</span><span class="special">)</span>
+ <span class="special">;</span>
+
+ <span class="identifier">xml</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"xml"</span><span class="special">);</span>
+ <span class="identifier">node</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"node"</span><span class="special">);</span>
+ <span class="identifier">text</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"text"</span><span class="special">);</span>
+ <span class="identifier">start_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"start_tag"</span><span class="special">);</span>
+ <span class="identifier">end_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"end_tag"</span><span class="special">);</span>
+
+ <span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">fail</span><span class="special">&gt;</span>
+ <span class="special">(</span>
+ <span class="identifier">xml</span>
+ <span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"Error! Expecting "</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">_4</span> <span class="comment">// what failed?
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">" here: \""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">construct</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">)</span> <span class="comment">// iterators to error-pos, end
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"\""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
+ <span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml</span><span class="special">(),</span> <span class="identifier">locals</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;,</span> <span class="identifier">space_type</span><span class="special">&gt;</span> <span class="identifier">xml</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">mini_xml_node</span><span class="special">(),</span> <span class="identifier">space_type</span><span class="special">&gt;</span> <span class="identifier">node</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</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">space_type</span><span class="special">&gt;</span> <span class="identifier">text</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</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">space_type</span><span class="special">&gt;</span> <span class="identifier">start_tag</span><span class="special">;</span>
+ <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">void</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">space_type</span><span class="special">&gt;</span> <span class="identifier">end_tag</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+ </p>
+<p>
+ What's new?
+ </p>
+<a name="spirit.qi_and_karma.abstracts.mini_xml___error_handling.readable_names"></a><h5>
+<a name="id484146"></a>
+ <a href="mini_xml___error_handling.html#spirit.qi_and_karma.abstracts.mini_xml___error_handling.readable_names">Readable
+ Names</a>
+ </h5>
+<p>
+ First, when we call the base class, we give the grammar a name:
+ </p>
+<pre class="programlisting">
+<span class="special">:</span> <span class="identifier">mini_xml_grammar</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">xml</span><span class="special">,</span> <span class="string">"xml"</span><span class="special">)</span>
+</pre>
+<p>
+ Then, we name all our rules:
+ </p>
+<pre class="programlisting">
+<span class="identifier">xml</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"xml"</span><span class="special">);</span>
+<span class="identifier">node</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"node"</span><span class="special">);</span>
+<span class="identifier">text</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"text"</span><span class="special">);</span>
+<span class="identifier">start_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"start_tag"</span><span class="special">);</span>
+<span class="identifier">end_tag</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="string">"end_tag"</span><span class="special">);</span>
+</pre>
+<a name="spirit.qi_and_karma.abstracts.mini_xml___error_handling.on_error"></a><h5>
+<a name="id484400"></a>
+ <a href="mini_xml___error_handling.html#spirit.qi_and_karma.abstracts.mini_xml___error_handling.on_error">On
+ Error</a>
+ </h5>
+<p>
+ <tt class="computeroutput"><span class="identifier">on_error</span></tt> declares our error
+ handler:
+ </p>
+<pre class="programlisting">
+<span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">Action</span><span class="special">&gt;(</span><span class="identifier">rule</span><span class="special">,</span> <span class="identifier">handler</span><span class="special">)</span>
+</pre>
+<p>
+ This will specify what we will do when we get an error. We will print out
+ an error message using phoenix:
+ </p>
+<pre class="programlisting">
+<span class="identifier">on_error</span><span class="special">&lt;</span><span class="identifier">fail</span><span class="special">&gt;</span>
+<span class="special">(</span>
+ <span class="identifier">xml</span>
+ <span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"Error! Expecting "</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">_4</span> <span class="comment">// what failed?
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">" here: \""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">construct</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">)</span> <span class="comment">// iterators to error-pos, end
+</span> <span class="special">&lt;&lt;</span> <span class="identifier">val</span><span class="special">(</span><span class="string">"\""</span><span class="special">)</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
+<span class="special">);</span>
+</pre>
+<p>
+ we choose to <tt class="computeroutput"><span class="identifier">fail</span></tt> in our
+ example for the <tt class="computeroutput"><span class="identifier">Action</span></tt>:
+ Quit and fail. Return a no_match (false). It can be one of:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ <tt class="computeroutput"><span class="identifier">Action</span></tt>
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ fail
+ </p>
+ </td>
+<td>
+ <p>
+ Quit and fail. Return a no_match.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ retry
+ </p>
+ </td>
+<td>
+ <p>
+ Attempt error recovery, possibly moving the iterator position.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ accept
+ </p>
+ </td>
+<td>
+ <p>
+ Force success, moving the iterator position appropriately.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ rethrow
+ </p>
+ </td>
+<td>
+ <p>
+ Rethrows the error.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+<p>
+ <tt class="computeroutput"><span class="identifier">rule</span></tt> is the rule we attach
+ the handler to. In our case, we are attaching to the <tt class="computeroutput"><span class="identifier">xml</span></tt>
+ rule.
+ </p>
+<p>
+ <tt class="computeroutput"><span class="identifier">handler</span></tt> is the actual error
+ handling function. It expects 4 arguments:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Arg
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ first
+ </p>
+ </td>
+<td>
+ <p>
+ The position of the iterator when the rule with the handler was
+ entered.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ last
+ </p>
+ </td>
+<td>
+ <p>
+ The end of input.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ error-pos
+ </p>
+ </td>
+<td>
+ <p>
+ The actual position of the iterator where the error occurred.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ what
+ </p>
+ </td>
+<td>
+ <p>
+ What failed: a string decribing the failure.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+<a name="spirit.qi_and_karma.abstracts.mini_xml___error_handling.expectation_points"></a><h5>
+<a name="id485068"></a>
+ <a href="mini_xml___error_handling.html#spirit.qi_and_karma.abstracts.mini_xml___error_handling.expectation_points">Expectation
+ Points</a>
+ </h5>
+<p>
+ You might not have noticed it, but some of our expressions changed from
+ using the <tt class="computeroutput"><span class="special">&gt;&gt;</span></tt> to <tt class="computeroutput"><span class="special">&gt;</span></tt>. Look, for example:
+ </p>
+<pre class="programlisting">
+<span class="identifier">end_tag</span> <span class="special">=</span>
+ <span class="string">"&lt;/"</span>
+ <span class="special">&gt;</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">_r1</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="char">'&gt;'</span>
+<span class="special">;</span>
+</pre>
+<p>
+ What is it? It's the <span class="emphasis"><em>expectation</em></span> operator. You will
+ have some "deterministic points" in the grammar. Those are the
+ places where backtracking <span class="bold"><b>cannot</b></span> occur.
+ For our example above, when you get a <tt class="computeroutput"><span class="string">"&lt;/"</span></tt>,
+ you definitely must see a valid end-tag label next. It should be the one
+ you got from the start-tag. After that, you definitely must have a <tt class="computeroutput"><span class="char">'&gt;'</span></tt> next. Otherwise, there is no point in
+ proceeding forward and trying other branches, regardless where they are.
+ The input is definitely erroneous. When this happens, an expectation_failure
+ exception is thrown. Somewhere outward, the error handler will catch the
+ exception.
+ </p>
+<p>
+ Try building the parser: ../../example/qi/mini_xml2.cpp.
+ You can find some examples in: ../../example/qi/mini_xml_samples
+ for testing purposes. "4.toyxml" has an error in it:
+ </p>
+<pre class="programlisting">
+<span class="special">&lt;</span><span class="identifier">foo</span><span class="special">&gt;&lt;</span><span class="identifier">bar</span><span class="special">&gt;&lt;/</span><span class="identifier">foo</span><span class="special">&gt;&lt;/</span><span class="identifier">bar</span><span class="special">&gt;</span>
+</pre>
+<p>
+ Running the example with this gives you:
+ </p>
+<pre class="programlisting">
+<span class="identifier">Error</span><span class="special">!</span> <span class="identifier">Expecting</span> <span class="string">"bar"</span> <span class="identifier">here</span><span class="special">:</span> <span class="string">"foo&gt;&lt;/bar&gt;"</span>
+<span class="identifier">Error</span><span class="special">!</span> <span class="identifier">Expecting</span> <span class="identifier">end_tag</span> <span class="identifier">here</span><span class="special">:</span> <span class="string">"&lt;bar&gt;&lt;/foo&gt;&lt;/bar&gt;"</span>
+<span class="special">-------------------------</span>
+<span class="identifier">Parsing</span> <span class="identifier">failed</span>
+<span class="special">-------------------------</span>
+</pre>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2001-2008 Joel de Guzman,
+ Hartmut Kaiser<p>
+ Distributed under 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="debugging.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="parse_trees_and_asts.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parse_trees_and_asts.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parse_trees_and_asts.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parse_trees_and_asts.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -7,8 +7,8 @@
 <meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
 <link rel="start" href="../../../index.html" title="Spirit 2.0">
 <link rel="up" href="../abstracts.html" title="Abstracts">
-<link rel="prev" href="error_handling.html" title="Error
- Handling">
+<link rel="prev" href="mini_xml___error_handling.html" title="Mini
+ XML - Error Handling">
 <link rel="next" href="../quick_reference.html" title="Quick Reference">
 </head>
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -22,7 +22,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="error_handling.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../quick_reference.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="mini_xml___error_handling.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../quick_reference.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 <div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title">
 <a name="spirit.qi_and_karma.abstracts.parse_trees_and_asts"></a><a href="parse_trees_and_asts.html" title="Parse
@@ -39,7 +39,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="error_handling.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../quick_reference.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="mini_xml___error_handling.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../quick_reference.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 </body>
 </html>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -56,27 +56,27 @@
           main reason for Spirit's extensibility.
         </p>
 <a name="spirit.qi_and_karma.abstracts.parsing.the_api_functions_exposed_by__emphasis_spirit_qi__emphasis__"></a><h5>
-<a name="id479245"></a>
+<a name="id482262"></a>
           <a href="parsing.html#spirit.qi_and_karma.abstracts.parsing.the_api_functions_exposed_by__emphasis_spirit_qi__emphasis__">The
           API functions exposed by <span class="emphasis"><em>Spirit.Qi</em></span> </a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing.the_parse___function"></a><h5>
-<a name="id479277"></a>
+<a name="id482294"></a>
           <a href="parsing.html#spirit.qi_and_karma.abstracts.parsing.the_parse___function">The
           parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing.the_phrase_parse___function"></a><h5>
-<a name="id479306"></a>
+<a name="id482323"></a>
           <a href="parsing.html#spirit.qi_and_karma.abstracts.parsing.the_phrase_parse___function">The
           phrase_parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing.the_tokenize_and_parse___function"></a><h5>
-<a name="id479333"></a>
+<a name="id482350"></a>
           <a href="parsing.html#spirit.qi_and_karma.abstracts.parsing.the_tokenize_and_parse___function">The
           tokenize_and_parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing.the_tokenize_and_phrase_parse___function"></a><h5>
-<a name="id479362"></a>
+<a name="id482380"></a>
           <a href="parsing.html#spirit.qi_and_karma.abstracts.parsing.the_tokenize_and_phrase_parse___function">The
           tokenize_and_phrase_parse() function</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing_and_generating.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing_and_generating.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/abstracts/parsing_and_generating.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -29,27 +29,27 @@
         and Generating">Parsing
         and Generating</a></h4></div></div></div>
 <a name="spirit.qi_and_karma.abstracts.parsing_and_generating.the_api_functions_exposed_by__emphasis_spirit_qi__emphasis__"></a><h5>
-<a name="id479420"></a>
+<a name="id482437"></a>
           <a href="parsing_and_generating.html#spirit.qi_and_karma.abstracts.parsing_and_generating.the_api_functions_exposed_by__emphasis_spirit_qi__emphasis__">The
           API functions exposed by <span class="emphasis"><em>Spirit.Qi</em></span> </a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing_and_generating.the_parse___function"></a><h5>
-<a name="id479455"></a>
+<a name="id482472"></a>
           <a href="parsing_and_generating.html#spirit.qi_and_karma.abstracts.parsing_and_generating.the_parse___function">The
           parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing_and_generating.the_phrase_parse___function"></a><h5>
-<a name="id479485"></a>
+<a name="id482503"></a>
           <a href="parsing_and_generating.html#spirit.qi_and_karma.abstracts.parsing_and_generating.the_phrase_parse___function">The
           phrase_parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing_and_generating.the_tokenize_and_parse___function"></a><h5>
-<a name="id479514"></a>
+<a name="id482532"></a>
           <a href="parsing_and_generating.html#spirit.qi_and_karma.abstracts.parsing_and_generating.the_tokenize_and_parse___function">The
           tokenize_and_parse() function</a>
         </h5>
 <a name="spirit.qi_and_karma.abstracts.parsing_and_generating.the_tokenize_and_phrase_parse___function"></a><h5>
-<a name="id479546"></a>
+<a name="id482563"></a>
           <a href="parsing_and_generating.html#spirit.qi_and_karma.abstracts.parsing_and_generating.the_tokenize_and_phrase_parse___function">The
           tokenize_and_phrase_parse() function</a>
         </h5>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/quick_reference.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/quick_reference.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/quick_reference.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -46,7 +46,7 @@
 </dl>
 </div>
 <div class="table">
-<a name="id479886"></a><p class="title"><b>Table 4. Character Parsers</b></p>
+<a name="id485566"></a><p class="title"><b>Table 4. Character Parsers</b></p>
 <table class="table" summary="Character Parsers">
 <colgroup>
 <col>

Modified: trunk/libs/spirit/doc/html/spirit/qi_and_karma/reference.html
==============================================================================
--- trunk/libs/spirit/doc/html/spirit/qi_and_karma/reference.html (original)
+++ trunk/libs/spirit/doc/html/spirit/qi_and_karma/reference.html 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -50,7 +50,7 @@
 <div class="titlepage"><div><div><h5 class="title">
 <a name="spirit.qi_and_karma.reference.concepts.parser"></a>Parser</h5></div></div></div>
 <a name="spirit.qi_and_karma.reference.concepts.parser.description"></a><h6>
-<a name="id480802"></a>
+<a name="id486482"></a>
             <a href="reference.html#spirit.qi_and_karma.reference.concepts.parser.description">Description</a>
           </h6>
 <p>
@@ -66,7 +66,7 @@
 </dl>
 </div>
 <a name="spirit.qi_and_karma.reference.concepts.parser.valid_expressions"></a><h6>
-<a name="id480862"></a>
+<a name="id486542"></a>
             <a href="reference.html#spirit.qi_and_karma.reference.concepts.parser.valid_expressions">Valid
             Expressions</a>
           </h6>
@@ -126,7 +126,7 @@
 </tr></tbody>
 </table></div>
 <a name="spirit.qi_and_karma.reference.concepts.parser.type_requirements"></a><h6>
-<a name="id480999"></a>
+<a name="id486680"></a>
             <a href="reference.html#spirit.qi_and_karma.reference.concepts.parser.type_requirements">Type
             Requirements</a>
           </h6>
@@ -161,14 +161,14 @@
 </tr></tbody>
 </table></div>
 <a name="spirit.qi_and_karma.reference.concepts.parser.invariants"></a><h6>
-<a name="id481103"></a>
+<a name="id486784"></a>
             <a href="reference.html#spirit.qi_and_karma.reference.concepts.parser.invariants">Invariants</a>
           </h6>
 <p>
             For any Parser xxx the following invariants always hold:
           </p>
 <a name="spirit.qi_and_karma.reference.concepts.parser.models"></a><h6>
-<a name="id481133"></a>
+<a name="id486815"></a>
             <a href="reference.html#spirit.qi_and_karma.reference.concepts.parser.models">Models</a>
           </h6>
 <p>

Modified: trunk/libs/spirit/doc/qi_and_karma.qbk
==============================================================================
--- trunk/libs/spirit/doc/qi_and_karma.qbk (original)
+++ trunk/libs/spirit/doc/qi_and_karma.qbk 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -20,6 +20,7 @@
 [include qi_and_karma/roman.qbk]
 [include qi_and_karma/employee.qbk]
 [include qi_and_karma/mini_xml.qbk]
+[include qi_and_karma/error_handling.qbk]
 [endsect]
 
 [section Abstracts]

Modified: trunk/libs/spirit/doc/qi_and_karma/error_handling.qbk
==============================================================================
--- trunk/libs/spirit/doc/qi_and_karma/error_handling.qbk (original)
+++ trunk/libs/spirit/doc/qi_and_karma/error_handling.qbk 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -6,5 +6,116 @@
     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 ===============================================================================/]
 
-[section Error Handling]
+[section Mini XML - Error Handling]
+
+A parser will not be complete without error handling. Spirit2 provides some
+facilities to make it easy to adapt a grammar for error handling. We'll wrap up
+the Qi tutorial with another version of the mini xml parser, this time, with
+error handling.
+
+[@../../example/qi/mini_xml1.cpp] and here: [@../../example/qi/mini_xml2.cpp]
+
+[import ../../example/qi/mini_xml3.cpp]
+
+Here's the grammar:
+
+[tutorial_xml3_grammar]
+
+What's new?
+
+[heading Readable Names]
+
+First, when we call the base class, we give the grammar a name:
+
+ : mini_xml_grammar::base_type(xml, "xml")
+
+Then, we name all our rules:
+
+ xml.name("xml");
+ node.name("node");
+ text.name("text");
+ start_tag.name("start_tag");
+ end_tag.name("end_tag");
+
+[heading On Error]
+
+`on_error` declares our error handler:
+
+ on_error<Action>(rule, handler)
+
+This will specify what we will do when we get an error. We will print out an
+error message using phoenix:
+
+ on_error<fail>
+ (
+ xml
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+
+we choose to `fail` in our example for the `Action`: Quit and fail. Return a
+no_match (false). It can be one of:
+
+[table
+ [[`Action`] [Description]]
+ [[fail] [Quit and fail. Return a no_match.]]
+ [[retry] [Attempt error recovery, possibly moving the iterator position.]]
+ [[accept] [Force success, moving the iterator position appropriately.]]
+ [[rethrow] [Rethrows the error.]]
+]
+
+
+`rule` is the rule we attach the handler to. In our case, we are attaching to the
+`xml` rule.
+
+`handler` is the actual error handling function. It expects 4 arguments:
+
+[table
+ [[Arg] [Description]]
+ [[first] [The position of the iterator when the rule with the handler was entered.]]
+ [[last] [The end of input.]]
+ [[error-pos] [The actual position of the iterator where the error occurred.]]
+ [[what] [What failed: a string decribing the failure.]]
+]
+
+[heading Expectation Points]
+
+You might not have noticed it, but some of our expressions changed from using
+the `>>` to `>`. Look, for example:
+
+ end_tag =
+ "</"
+ > lit(_r1)
+ > '>'
+ ;
+
+What is it? It's the /expectation/ operator. You will have some "deterministic
+points" in the grammar. Those are the places where backtracking *cannot* occur.
+For our example above, when you get a `"</"`, you definitely must see a valid
+end-tag label next. It should be the one you got from the start-tag. After that,
+you definitely must have a `'>'` next. Otherwise, there is no point in
+proceeding forward and trying other branches, regardless where they are. The
+input is definitely erroneous. When this happens, an expectation_failure
+exception is thrown. Somewhere outward, the error handler will catch the
+exception.
+
+Try building the parser: [@../../example/qi/mini_xml2.cpp]. You can find some
+examples in: [@../../example/qi/mini_xml_samples] for testing purposes.
+"4.toyxml" has an error in it:
+
+ <foo><bar></foo></bar>
+
+Running the example with this gives you:
+
+ Error! Expecting "bar" here: "foo></bar>"
+ Error! Expecting end_tag here: "<bar></foo></bar>"
+ -------------------------
+ Parsing failed
+ -------------------------
+
 [endsect]

Modified: trunk/libs/spirit/doc/qi_and_karma/mini_xml.qbk
==============================================================================
--- trunk/libs/spirit/doc/qi_and_karma/mini_xml.qbk (original)
+++ trunk/libs/spirit/doc/qi_and_karma/mini_xml.qbk 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -24,6 +24,8 @@
 * Inherited attributes
 * Variant attributes
 * Local Variables
+* Not Predicate
+* Lazy Lit
 
 The full cpp files for these examples can be found here:
 [@../../example/qi/mini_xml1.cpp] and here: [@../../example/qi/mini_xml2.cpp]
@@ -69,12 +71,27 @@
 
     start_tag =
             '<'
+ >> !char_('/')
>> lexeme[+(char_ - '>') [_val += _1]]
>> '>'
     ;
 
-Nothing special. Almost the same as the `text` rule apart from the added `'<'`
-and `'>'`.
+[heading Not Predicate]
+
+`start_tag` is similar to the `text` rule apart from the added `'<'` and `'>'`.
+But wait, to make sure that the `start_tag` does not parse `end_tag`s too, we
+add: `!char_('/')`. This is a "Not Predicate":
+
+ !p
+
+It will try the parser, `p`. If it is successful, fail, otherwise, pass. In
+other words, it negates the result of `p`. Like the `eps`, it does not consume
+any input though. It will always rewind the iterator position to where it
+was upon entry. So, the expression:
+
+ !char_('/')
+
+basically says: we should not have a `'/'` at this point.
 
 [heading Inherited Attribute]
 
@@ -207,7 +224,7 @@
 # Upon parsing `start_tag`, the parsed start-tag string is placed in
   the local variable specified by (yet another) __phoenix__ placeholder:
   `_a`. We have only one local variable. If we had more, these are designated
- by `_b`..`z`.
+ by `_b`..`_z`.
 
 # Then we parse zero or more `node`s.
 

Modified: trunk/libs/spirit/example/qi/mini_xml1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml1.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml1.cpp 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -142,6 +142,7 @@
 
         start_tag =
                 '<'
+ >> !char_('/')
>> lexeme[+(char_ - '>') [_val += _1]]
>> '>'
         ;

Modified: trunk/libs/spirit/example/qi/mini_xml2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml2.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml2.cpp 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -140,6 +140,7 @@
 
         start_tag %=
                 '<'
+ >> !char_('/')
>> lexeme[+(char_ - '>')]
>> '>'
         ;

Added: trunk/libs/spirit/example/qi/mini_xml3.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/mini_xml3.cpp 2008-07-13 02:49:40 EDT (Sun, 13 Jul 2008)
@@ -0,0 +1,248 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A mini XML-like parser
+//
+// [ JDG March 25, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_fusion.hpp>
+#include <boost/spirit/include/phoenix_stl.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/variant/recursive_variant.hpp>
+#include <boost/foreach.hpp>
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+using namespace boost::spirit;
+using namespace boost::spirit::qi;
+using namespace boost::spirit::ascii;
+using namespace boost::spirit::arg_names;
+
+namespace fusion = boost::fusion;
+namespace phoenix = boost::phoenix;
+
+using phoenix::at_c;
+using phoenix::push_back;
+using phoenix::val;
+using phoenix::construct;
+
+///////////////////////////////////////////////////////////////////////////////
+// Our mini XML tree representation
+///////////////////////////////////////////////////////////////////////////////
+struct mini_xml;
+
+typedef
+ boost::variant<
+ boost::recursive_wrapper<mini_xml>
+ , std::string
+ >
+mini_xml_node;
+
+struct mini_xml
+{
+ std::string name; // tag name
+ std::vector<mini_xml_node> children; // children
+};
+
+// We need to tell fusion about our mini_xml struct
+// to make it a first-class fusion citizen
+BOOST_FUSION_ADAPT_STRUCT(
+ mini_xml,
+ (std::string, name)
+ (std::vector<mini_xml_node>, children)
+)
+
+///////////////////////////////////////////////////////////////////////////////
+// Print out the mini xml tree
+///////////////////////////////////////////////////////////////////////////////
+int const tabsize = 4;
+
+void tab(int indent)
+{
+ for (int i = 0; i < indent; ++i)
+ std::cout << ' ';
+}
+
+struct mini_xml_printer
+{
+ mini_xml_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const;
+
+ int indent;
+};
+
+struct mini_xml_node_printer : boost::static_visitor<>
+{
+ mini_xml_node_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const
+ {
+ mini_xml_printer(indent+tabsize)(xml);
+ }
+
+ void operator()(std::string const& text) const
+ {
+ tab(indent+tabsize);
+ std::cout << "text: \"" << text << '"' << std::endl;
+ }
+
+ int indent;
+};
+
+void mini_xml_printer::operator()(mini_xml const& xml) const
+{
+ tab(indent);
+ std::cout << "tag: " << xml.name << std::endl;
+ tab(indent);
+ std::cout << '{' << std::endl;
+
+ BOOST_FOREACH(mini_xml_node const& node, xml.children)
+ {
+ boost::apply_visitor(mini_xml_node_printer(indent), node);
+ }
+
+ tab(indent);
+ std::cout << '}' << std::endl;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Our mini XML grammar definition
+///////////////////////////////////////////////////////////////////////////////
+//[tutorial_xml3_grammar
+template <typename Iterator>
+struct mini_xml_grammar
+ : grammar<Iterator, mini_xml(), locals<std::string>, space_type>
+{
+ mini_xml_grammar()
+ : mini_xml_grammar::base_type(xml, "xml")
+ {
+ text %= lexeme[+(char_ - '<')];
+ node %= xml | text;
+
+ start_tag %=
+ '<'
+ >> !char_('/')
+ > lexeme[+(char_ - '>')]
+ > '>'
+ ;
+
+ end_tag =
+ "</"
+ > lit(_r1)
+ > '>'
+ ;
+
+ xml %=
+ start_tag[_a = _1]
+ > *node
+ > end_tag(_a)
+ ;
+
+ xml.name("xml");
+ node.name("node");
+ text.name("text");
+ start_tag.name("start_tag");
+ end_tag.name("end_tag");
+
+ on_error<fail>
+ (
+ xml
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+ }
+
+ rule<Iterator, mini_xml(), locals<std::string>, space_type> xml;
+ rule<Iterator, mini_xml_node(), space_type> node;
+ rule<Iterator, std::string(), space_type> text;
+ rule<Iterator, std::string(), space_type> start_tag;
+ rule<Iterator, void(std::string), space_type> end_tag;
+};
+//]
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ char const* filename;
+ if (argc > 1)
+ {
+ filename = argv[1];
+ }
+ else
+ {
+ std::cerr << "Error: No input file provided." << std::endl;
+ return 1;
+ }
+
+ std::ifstream in(filename, std::ios_base::in);
+
+ if (!in)
+ {
+ std::cerr << "Error: Could not open input file: "
+ << filename << std::endl;
+ return 1;
+ }
+
+ std::string storage; // We will read the contents here.
+ in.unsetf(std::ios::skipws); // No white space skipping!
+ std::copy(
+ std::istream_iterator<char>(in),
+ std::istream_iterator<char>(),
+ std::back_inserter(storage));
+
+ typedef mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
+ mini_xml_grammar xml; // Our grammar
+ mini_xml ast; // our tree
+
+ std::string::const_iterator iter = storage.begin();
+ std::string::const_iterator end = storage.end();
+ bool r = phrase_parse(iter, end, xml, ast, space);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "-------------------------\n";
+ mini_xml_printer printer;
+ printer(ast);
+ return 0;
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ return 1;
+ }
+}
+
+


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