Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59710 - in trunk/tools/quickbook: detail test
From: daniel_james_at_[hidden]
Date: 2010-02-16 17:33:50


Author: danieljames
Date: 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
New Revision: 59710
URL: http://svn.boost.org/trac/boost/changeset/59710

Log:
Deal with mismatched section tags in templates.
Added:
   trunk/tools/quickbook/test/fail-template-section-1.quickbook (contents, props changed)
   trunk/tools/quickbook/test/fail-template-section-2.quickbook (contents, props changed)
   trunk/tools/quickbook/test/fail-template-section-3.quickbook (contents, props changed)
   trunk/tools/quickbook/test/template-section.gold (contents, props changed)
   trunk/tools/quickbook/test/template-section.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/detail/actions.cpp | 29 ++++++++++++++++++++++-------
   trunk/tools/quickbook/detail/actions.hpp | 3 +++
   trunk/tools/quickbook/detail/actions_class.cpp | 7 +++++--
   trunk/tools/quickbook/detail/actions_class.hpp | 2 ++
   trunk/tools/quickbook/test/Jamfile.v2 | 4 ++++
   5 files changed, 36 insertions(+), 9 deletions(-)

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -787,6 +787,10 @@
         std::string result;
         actions.push(); // scope the actions' states
         {
+ // Store the current section level so that we can ensure that
+ // [section] and [endsect] tags in the template are balanced.
+ actions.min_section_level = actions.section_level;
+
             template_symbol const* symbol =
                 actions.templates.find(actions.template_info[0]);
             BOOST_ASSERT(symbol);
@@ -849,6 +853,17 @@
                 ++actions.error_count;
                 return;
             }
+
+ if (actions.section_level != actions.min_section_level)
+ {
+ boost::spirit::classic::file_position const pos = first.get_position();
+ detail::outerr(pos.file,pos.line)
+ << "Mismatched sections in template " << template_info[0] << std::endl;
+ actions.pop(); // restore the actions' states
+ --actions.template_depth;
+ ++actions.error_count;
+ return;
+ }
         }
 
         actions.pop(); // restore the actions' states
@@ -1056,19 +1071,19 @@
 
     void end_section_action::operator()(iterator first, iterator last) const
     {
- out << "</section>";
-
- --section_level;
- if (section_level < 0)
+ if (section_level <= min_section_level)
         {
             boost::spirit::classic::file_position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Mismatched [endsect] near column " << pos.column << ".\n";
             ++error_count;
             
- // $$$ TODO: somehow fail parse else BOOST_ASSERT(std::string::npos != n)
- // $$$ below will assert.
+ return;
         }
+
+ --section_level;
+ out << "</section>";
+
         if (section_level == 0)
         {
             qualified_section_id.clear();
@@ -1077,7 +1092,7 @@
         {
             std::string::size_type const n =
                 qualified_section_id.find_last_of('.');
- BOOST_ASSERT(std::string::npos != n);
+ if(std::string::npos != n);
             qualified_section_id.erase(n, std::string::npos);
         }
     }

Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -715,10 +715,12 @@
         end_section_action(
             collector& out
           , int& section_level
+ , int& min_section_level
           , std::string& qualified_section_id
           , int& error_count)
         : out(out)
         , section_level(section_level)
+ , min_section_level(min_section_level)
         , qualified_section_id(qualified_section_id)
         , error_count(error_count) {}
 
@@ -726,6 +728,7 @@
 
         collector& out;
         int& section_level;
+ int& min_section_level;
         std::string& qualified_section_id;
         int& error_count;
    };

Modified: trunk/tools/quickbook/detail/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.cpp (original)
+++ trunk/tools/quickbook/detail/actions_class.cpp 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -47,6 +47,7 @@
         , outdir(outdir_)
         , macro()
         , section_level(0)
+ , min_section_level(0)
         , section_id()
         , qualified_section_id()
         , source_mode("c++")
@@ -172,7 +173,7 @@
         , anchor(out)
 
         , begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id, element_id)
- , end_section(out, section_level, qualified_section_id, error_count)
+ , end_section(out, section_level, min_section_level, qualified_section_id, error_count)
         , xinclude(out, *this)
         , include(*this)
         , import(out, *this)
@@ -201,6 +202,7 @@
               , outdir
               , macro
               , section_level
+ , min_section_level
               , section_id
               , qualified_section_id
               , source_mode
@@ -212,7 +214,7 @@
         temp.push();
         temp_para.push();
         list_buffer.push();
- templates.push();
+ templates.push();
     }
 
     void actions::pop()
@@ -222,6 +224,7 @@
           , outdir
           , macro
           , section_level
+ , min_section_level
           , section_id
           , qualified_section_id
           , source_mode

Modified: trunk/tools/quickbook/detail/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.hpp (original)
+++ trunk/tools/quickbook/detail/actions_class.hpp 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -62,6 +62,7 @@
         fs::path outdir;
         string_symbols macro;
         int section_level;
+ int min_section_level;
         std::string section_id;
         std::string qualified_section_id;
         std::string source_mode;
@@ -71,6 +72,7 @@
           , fs::path
           , string_symbols
           , int
+ , int
           , std::string
           , std::string
           , std::string>

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -23,6 +23,7 @@
     [ quickbook-test templates ]
     [ quickbook-test templates_1_4 ]
     [ quickbook-test templates_1_5 ]
+ [ quickbook-test template-section ]
     #[ quickbook-test xinclude ]
     [ quickbook-test import ]
     [ quickbook-test include_1_5 ]
@@ -43,6 +44,9 @@
     [ quickbook-fail-test fail-parse-error1 ]
     [ quickbook-fail-test fail-parse-error2 ]
     [ quickbook-fail-test fail-template-lookup1 ]
+ [ quickbook-fail-test fail-template-section-1 ]
+ [ quickbook-fail-test fail-template-section-2 ]
+ [ quickbook-fail-test fail-template-section-3 ]
     [ quickbook-test utf-8 ]
     [ quickbook-test utf-8-bom ]
     [ quickbook-fail-test utf-16be-bom ]

Added: trunk/tools/quickbook/test/fail-template-section-1.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/fail-template-section-1.quickbook 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -0,0 +1,9 @@
+[article Template should contain balanced sections
+ [quickbook 1.5]
+]
+
+[template begin_no_end[]
+[section Test]
+]
+
+[begin_no_end]
\ No newline at end of file

Added: trunk/tools/quickbook/test/fail-template-section-2.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/fail-template-section-2.quickbook 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -0,0 +1,10 @@
+[article Template should contain balanced sections
+ [quickbook 1.5]
+]
+
+[template end_before_begin[]
+[endsect]
+[section Test]
+]
+
+[end_before_begin]
\ No newline at end of file

Added: trunk/tools/quickbook/test/fail-template-section-3.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/fail-template-section-3.quickbook 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -0,0 +1,9 @@
+[article Template should contain balanced sections
+ [quickbook 1.5]
+]
+
+[template end_no_begin[]
+[endsect]
+]
+
+[end_no_begin]
\ No newline at end of file

Added: trunk/tools/quickbook/test/template-section.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/template-section.gold 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="section_in_a_template" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Section in a template</title>
+ <articleinfo>
+ </articleinfo>
+ <para>
+ <para>
+ It's a pity if the whole template is wrapped in a paragraph.
+ </para>
+ <section id="section_in_a_template.test">
+ <title><link linkend="section_in_a_template.test">Test</link></title>
+ <para>
+ Hello.
+ </para>
+ <anchor id="section_in_a_template.test.just_to_test_id_generation"/>
+ <bridgehead renderas="sect3">
+ <link linkend="section_in_a_template.test.just_to_test_id_generation">Just
+ to test id generation</link>
+ </bridgehead>
+ <para>
+ Goodbye.
+ </para>
+ </section>
+ </para>
+</article>

Added: trunk/tools/quickbook/test/template-section.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/template-section.quickbook 2010-02-16 17:33:49 EST (Tue, 16 Feb 2010)
@@ -0,0 +1,20 @@
+[article Section in a template
+ [quickbook 1.5]
+]
+
+[template nestedsection[]
+
+It's a pity if the whole template is wrapped in a paragraph.
+
+[section Test]
+
+Hello.
+
+[heading Just to test id generation]
+
+Goodbye.
+
+[endsect]
+]
+
+[nestedsection]
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk