Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75538 - in branches/quickbook-dev/tools/quickbook: src test/doc-info
From: dnljms_at_[hidden]
Date: 2011-11-17 16:07:02


Author: danieljames
Date: 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
New Revision: 75538
URL: http://svn.boost.org/trac/boost/changeset/75538

Log:
Quickbook: Fail gracefully if document info is missing.

I also tweaked `pre` and `post` a bit while I was at it.
Added:
   branches/quickbook-dev/tools/quickbook/test/doc-info/missing_doc_info-1_6-fail.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.hpp | 4 +-
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 71 ++++++++++++++++++++++-----------------
   branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 7 ++-
   branches/quickbook-dev/tools/quickbook/test/doc-info/Jamfile.v2 | 1
   4 files changed, 48 insertions(+), 35 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
@@ -302,8 +302,8 @@
    };
 
     // Returns the doc_type, or an empty string if there isn't one.
- std::string pre(collector& out, quickbook::actions& actions, value include_doc_id, bool nested_file);
- void post(collector& out, quickbook::actions& actions, std::string const& doc_type);
+ std::string pre(quickbook::actions& actions, parse_iterator pos, value include_doc_id, bool nested_file);
+ void post(quickbook::actions& actions, std::string const& doc_type);
 
     struct to_value_scoped_action : scoped_action_base
     {

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
@@ -104,7 +104,7 @@
             
                 if(result < 100 || result > 106)
                 {
- detail::outerr(actions.current_file->path, 1)
+ detail::outerr(actions.current_file->path)
                         << "Unknown version: "
                         << major_verison
                         << "."
@@ -118,7 +118,7 @@
         return result;
     }
 
- std::string pre(collector& out, quickbook::actions& actions,
+ std::string pre(quickbook::actions& actions, parse_iterator pos,
             value include_doc_id, bool nested_file)
     {
         // The doc_info in the file has been parsed. Here's what we'll do
@@ -136,6 +136,7 @@
         bool use_doc_info = false;
         std::string doc_type;
         value doc_title;
+
         if (values.check(doc_info_tags::type))
         {
             doc_type = values.consume(doc_info_tags::type).get_quickbook();
@@ -146,11 +147,18 @@
         {
             if (!nested_file)
             {
- detail::outerr(actions.current_file->path, 1)
+ detail::outerr(actions.current_file, pos.base())
                     << "No doc_info block."
                     << std::endl;
 
                 ++actions.error_count;
+
+ // Create a fake document info block in order to continue.
+ doc_type = "article";
+ doc_title = qbk_value_ref(actions.current_file,
+ pos.base(), pos.base(),
+ doc_info_tags::type);
+ use_doc_info = true;
             }
         }
 
@@ -177,7 +185,8 @@
 
         if(!duplicates.empty())
         {
- detail::outwarn(actions.current_file->path,1)
+ // TODO: This is the *end* of the document info.
+ detail::outwarn(actions.current_file, pos.base())
                 << (duplicates.size() > 1 ?
                     "Duplicate attributes" : "Duplicate attribute")
                 << ":" << detail::utf8(boost::algorithm::join(duplicates, ", "))
@@ -203,7 +212,7 @@
 
         if (new_version != qbk_version_n && new_version == 106)
         {
- detail::outwarn(actions.current_file->path,1)
+ detail::outwarn(actions.current_file->path)
                 << "Quickbook 1.6 is still under development and is "
                 "likely to change in the future." << std::endl;
         }
@@ -214,7 +223,7 @@
         else if (use_doc_info) {
             // hard code quickbook version to v1.1
             qbk_version_n = 101;
- detail::outwarn(actions.current_file->path,1)
+ detail::outwarn(actions.current_file, pos.base())
                 << "Quickbook version undefined. "
                 "Version 1.1 is assumed" << std::endl;
         }
@@ -277,7 +286,7 @@
 
             if(!invalid_attributes.empty())
             {
- detail::outwarn(actions.current_file->path,1)
+ detail::outwarn(actions.current_file->path)
                     << (invalid_attributes.size() > 1 ?
                         "Invalid attributes" : "Invalid attribute")
                     << " for '" << detail::utf8(doc_type) << " document info': "
@@ -291,7 +300,7 @@
 
         if (!nested_file)
         {
- out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ actions.out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                 << "<!DOCTYPE "
                 << doc_type
                 << " PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
@@ -299,51 +308,51 @@
                 ;
         }
 
- out << '<' << doc_type << "\n"
+ actions.out << '<' << doc_type << "\n"
             << " id=\""
             << id_placeholder
             << "\"\n";
 
         if(!lang.empty())
         {
- out << " lang=\""
+ actions.out << " lang=\""
                 << doc_info_output(lang, 106)
                 << "\"\n";
         }
 
         if(doc_type == "library" && !doc_title.empty())
         {
- out << " name=\"" << doc_info_output(doc_title, 106) << "\"\n";
+ actions.out << " name=\"" << doc_info_output(doc_title, 106) << "\"\n";
         }
 
         // Set defaults for dirname + last_revision
 
         if (!dirname.empty() || doc_type == "library")
         {
- out << " dirname=\"";
+ actions.out << " dirname=\"";
             if (!dirname.empty()) {
- out << doc_info_output(dirname, 106);
+ actions.out << doc_info_output(dirname, 106);
             }
             else if (!id_.empty()) {
- out << id_;
+ actions.out << id_;
             }
             else if (!include_doc_id_.empty()) {
- out << include_doc_id_;
+ actions.out << include_doc_id_;
             }
             else if (!doc_title.empty()) {
- out << detail::make_identifier(doc_title.get_quickbook());
+ actions.out << detail::make_identifier(doc_title.get_quickbook());
             }
             else {
- out << "library";
+ actions.out << "library";
             }
 
- out << "\"\n";
+ actions.out << "\"\n";
         }
 
- out << " last-revision=\"";
+ actions.out << " last-revision=\"";
         if (!last_revision.empty())
         {
- out << doc_info_output(last_revision, 106);
+ actions.out << doc_info_output(last_revision, 106);
         }
         else
         {
@@ -358,19 +367,19 @@
                 current_gm_time
             );
 
- out << strdate;
+ actions.out << strdate;
         }
 
- out << "\" \n";
+ actions.out << "\" \n";
 
         if (!xmlbase.empty())
         {
- out << " xml:base=\""
+ actions.out << " xml:base=\""
                 << xmlbase_value
                 << "\"\n";
         }
 
- out << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
+ actions.out << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
 
         std::ostringstream tmp;
 
@@ -486,13 +495,13 @@
         }
 
         if(doc_type != "library") {
- write_document_title(out, doc_title, version);
+ write_document_title(actions.out, doc_title, version);
         }
 
         std::string docinfo = tmp.str();
         if(!docinfo.empty())
         {
- out << " <" << doc_type << "info>\n"
+ actions.out << " <" << doc_type << "info>\n"
                 << docinfo
                 << " </" << doc_type << "info>\n"
                 << "\n"
@@ -500,13 +509,13 @@
         }
 
         if(doc_type == "library") {
- write_document_title(out, doc_title, version);
+ write_document_title(actions.out, doc_title, version);
         }
 
         return doc_type;
     }
-
- void post(collector& out, quickbook::actions& actions, std::string const& doc_type)
+
+ void post(quickbook::actions& actions, std::string const& doc_type)
     {
         // We've finished generating our output. Here's what we'll do
         // *after* everything else.
@@ -518,13 +527,13 @@
                 << std::endl;
 
             while(actions.ids.section_level() > 1) {
- out << "</section>";
+ actions.out << "</section>";
                 actions.ids.end_section();
             }
         }
 
         actions.ids.end_file();
- if (!doc_type.empty()) out << "\n</" << doc_type << ">\n\n";
+ if (!doc_type.empty()) actions.out << "\n</" << doc_type << ">\n\n";
     }
 
     static void write_document_title(collector& out, value const& title, value const& version)

Modified: branches/quickbook-dev/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/quickbook.cpp 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
@@ -78,13 +78,16 @@
         parse_iterator last(actor.current_file->source.end());
 
         cl::parse_info<parse_iterator> info = cl::parse(first, last, actor.grammar().doc_info);
+ assert(info.hit);
+
         if (!actor.error_count)
         {
- std::string doc_type = pre(actor.out, actor, include_doc_id, nested_file);
+ parse_iterator pos = info.stop;
+ std::string doc_type = pre(actor, pos, include_doc_id, nested_file);
 
             info = cl::parse(info.hit ? info.stop : first, last, actor.grammar().block);
 
- post(actor.out, actor, doc_type);
+ post(actor, doc_type);
 
             if (!info.full)
             {

Modified: branches/quickbook-dev/tools/quickbook/test/doc-info/Jamfile.v2
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/doc-info/Jamfile.v2 (original)
+++ branches/quickbook-dev/tools/quickbook/test/doc-info/Jamfile.v2 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
@@ -30,4 +30,5 @@
     [ quickbook-test empty_title-1_1 ]
     [ quickbook-test empty_title-1_5 ]
     [ quickbook-test empty_title-1_6 ]
+ [ quickbook-error-test missing_doc_info-1_6-fail ]
     ;

Added: branches/quickbook-dev/tools/quickbook/test/doc-info/missing_doc_info-1_6-fail.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/doc-info/missing_doc_info-1_6-fail.quickbook 2011-11-17 16:07:01 EST (Thu, 17 Nov 2011)
@@ -0,0 +1,3 @@
+[quickbook 1.6]
+
+Hello!


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