Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75526 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-17 16:03:26


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

Log:
Quickbook: Deal with doc attributes without doc info block.
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.hpp | 12 +----
   branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 3 -
   branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 1
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 75 +++++++++++++++++++++------------------
   branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp | 8 ++-
   branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 26 +++++--------
   6 files changed, 59 insertions(+), 66 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:03:25 EST (Thu, 17 Nov 2011)
@@ -301,15 +301,9 @@
         quickbook::actions& actions;
    };
 
- enum docinfo_types
- {
- docinfo_ignore = 0,
- docinfo_main = 1,
- docinfo_nested = 2
- };
-
- void pre(collector& out, quickbook::actions& actions, value include_doc_id, docinfo_types);
- void post(collector& out, quickbook::actions& actions, docinfo_types);
+ // 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);
 
     struct to_value_scoped_action : scoped_action_base
     {

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-11-17 16:03:25 EST (Thu, 17 Nov 2011)
@@ -34,7 +34,6 @@
         , ids(ids)
 
         , imported(false)
- , doc_type()
         , macro()
         , source_mode("c++")
         , current_file(0)
@@ -90,7 +89,6 @@
         , scope(scope)
         , qbk_version(qbk_version_n)
         , imported(a.imported)
- , doc_type(a.doc_type)
         , current_file(a.current_file)
         , filename_relative(a.filename_relative)
         , xinclude_base(a.xinclude_base)
@@ -111,7 +109,6 @@
         a.values.builder.restore();
         boost::swap(qbk_version_n, qbk_version);
         boost::swap(a.imported, imported);
- boost::swap(a.doc_type, doc_type);
         boost::swap(a.current_file, current_file);
         boost::swap(a.filename_relative, filename_relative);
         boost::swap(a.xinclude_base, xinclude_base);

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-11-17 16:03:25 EST (Thu, 17 Nov 2011)
@@ -52,7 +52,6 @@
 
     // state saved for files and templates.
         bool imported;
- std::string doc_type;
         string_symbols macro;
         std::string source_mode;
         file const* current_file;

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:03:25 EST (Thu, 17 Nov 2011)
@@ -111,8 +111,8 @@
         return result;
     }
 
- void pre(collector& out, quickbook::actions& actions,
- value include_doc_id, docinfo_types docinfo_type)
+ std::string pre(collector& out, quickbook::actions& actions,
+ value include_doc_id, bool nested_file)
     {
         // The doc_info in the file has been parsed. Here's what we'll do
         // *before* anything else.
@@ -125,16 +125,26 @@
         // Skip over invalid attributes
 
         while (values.check(value::default_tag)) values.consume();
-
+
+ bool use_doc_info = false;
+ std::string doc_type;
         value doc_title;
         if (values.check(doc_info_tags::type))
         {
- actions.doc_type = values.consume(doc_info_tags::type).get_quickbook();
+ doc_type = values.consume(doc_info_tags::type).get_quickbook();
             doc_title = values.consume(doc_info_tags::title);
+ use_doc_info = !nested_file || qbk_version_n >= 106u;
         }
         else
         {
- actions.doc_type.clear();
+ if (!nested_file)
+ {
+ detail::outerr(actions.current_file->path, 1)
+ << "No doc_info block."
+ << std::endl;
+
+ ++actions.error_count;
+ }
         }
 
         std::vector<std::string> duplicates;
@@ -185,7 +195,7 @@
 
         // Quickbook version
 
- unsigned new_version = get_version(actions, docinfo_type, qbk_version);
+ unsigned new_version = get_version(actions, use_doc_info, qbk_version);
         if (new_version != qbk_version_n && new_version == 106)
         {
             detail::outwarn(actions.current_file->path,1)
@@ -194,12 +204,12 @@
         }
 
         unsigned compatibility_version =
- get_version(actions, docinfo_type, compatibility_mode);
+ get_version(actions, use_doc_info, compatibility_mode);
 
         // if we're ignoring the document info, just start the file
         // and we're done.
 
- if (!docinfo_type)
+ if (!use_doc_info)
         {
             if (new_version) qbk_version_n = new_version;
             actions.current_file_tmp->version(qbk_version_n);
@@ -210,7 +220,7 @@
             actions.ids.start_file(compatibility_version, include_doc_id_, id_,
                     doc_title.check() ? doc_title.get_quickbook() : std::string());
 
- return;
+ return "";
         }
 
         // Otherwise we're starting a new (possiblity nested) document.
@@ -238,16 +248,9 @@
                 compatibility_version, include_doc_id_, id_,
                 doc_title.check() ? doc_title.get_quickbook() : std::string());
 
- // if we're ignoring the document info, we're done.
-
- if (!docinfo_type)
- {
- return;
- }
-
         // Make sure we really did have a document info block.
 
- assert(doc_title.check() && !actions.doc_type.empty() &&
+ assert(doc_title.check() && !doc_type.empty() &&
             !start_file_info.doc_id.empty());
 
         // Set xmlbase
@@ -264,7 +267,7 @@
 
         // Warn about invalid fields
 
- if (actions.doc_type != "library")
+ if (doc_type != "library")
         {
             std::vector<std::string> invalid_attributes;
 
@@ -282,7 +285,7 @@
                 detail::outwarn(actions.current_file->path,1)
                     << (invalid_attributes.size() > 1 ?
                         "Invalid attributes" : "Invalid attribute")
- << " for '" << detail::utf8(actions.doc_type) << " document info': "
+ << " for '" << detail::utf8(doc_type) << " document info': "
                     << detail::utf8(boost::algorithm::join(invalid_attributes, ", "))
                     << "\n"
                     ;
@@ -291,17 +294,17 @@
 
         // Write out header
 
- if (docinfo_type == docinfo_main)
+ if (!nested_file)
         {
             out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                 << "<!DOCTYPE "
- << actions.doc_type
+ << doc_type
                 << " PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
                 << " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">\n"
                 ;
         }
 
- out << '<' << actions.doc_type << "\n"
+ out << '<' << doc_type << "\n"
             << " id=\""
             << start_file_info.placeholder
             << "\"\n";
@@ -313,14 +316,14 @@
                 << "\"\n";
         }
 
- if(actions.doc_type == "library")
+ if(doc_type == "library")
         {
             out << " name=\"" << doc_info_output(doc_title, 106) << "\"\n";
         }
 
         // Set defaults for dirname + last_revision
 
- if(!dirname.empty() || actions.doc_type == "library")
+ if(!dirname.empty() || doc_type == "library")
         {
             out << " dirname=\"";
             if (!dirname.empty())
@@ -441,9 +444,9 @@
 
         if (!purpose.empty())
         {
- tmp << " <" << actions.doc_type << "purpose>\n"
+ tmp << " <" << doc_type << "purpose>\n"
                 << " " << doc_info_output(purpose, 103)
- << " </" << actions.doc_type << "purpose>\n"
+ << " </" << doc_type << "purpose>\n"
                 << "\n"
                 ;
         }
@@ -451,9 +454,9 @@
         BOOST_FOREACH(value_consumer values, categories) {
             value category = values.optional_consume();
             if(!category.empty()) {
- tmp << " <" << actions.doc_type << "category name=\"category:"
+ tmp << " <" << doc_type << "category name=\"category:"
                     << doc_info_output(category, 106)
- << "\"></" << actions.doc_type << "category>\n"
+ << "\"></" << doc_type << "category>\n"
                     << "\n"
                 ;
             }
@@ -475,32 +478,34 @@
             biblioid.finish();
         }
 
- if(actions.doc_type != "library") {
+ if(doc_type != "library") {
             write_document_title(out, doc_title, version);
         }
 
         std::string docinfo = tmp.str();
         if(!docinfo.empty())
         {
- out << " <" << actions.doc_type << "info>\n"
+ out << " <" << doc_type << "info>\n"
                 << docinfo
- << " </" << actions.doc_type << "info>\n"
+ << " </" << doc_type << "info>\n"
                 << "\n"
             ;
         }
 
- if(actions.doc_type == "library") {
+ if(doc_type == "library") {
             write_document_title(out, doc_title, version);
         }
+
+ return doc_type;
     }
     
- void post(collector& out, quickbook::actions& actions, docinfo_types docinfo_type)
+ void post(collector& out, quickbook::actions& actions, std::string const& doc_type)
     {
         // We've finished generating our output. Here's what we'll do
         // *after* everything else.
 
         // Close any open sections.
- if (docinfo_type && actions.ids.section_level() > 1) {
+ if (!doc_type.empty() && actions.ids.section_level() > 1) {
             detail::outwarn(actions.current_file->path)
                 << "Missing [endsect] detected at end of file."
                 << std::endl;
@@ -512,7 +517,7 @@
         }
 
         actions.ids.end_file();
- if (docinfo_type) out << "\n</" << actions.doc_type << ">\n\n";
+ if (!doc_type.empty()) 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/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp 2011-11-17 16:03:25 EST (Thu, 17 Nov 2011)
@@ -116,7 +116,7 @@
>> *( local.doc_attribute
>> space
                 )
- >> local.doc_info_block
+ >> !local.doc_info_block
             ;
 
         local.doc_info_block =
@@ -131,8 +131,10 @@
>> (*( local.doc_info_attribute
>> space
                 )) [actions.values.sort()]
- >> ']'
- >> (+eol | cl::end_p)
+ >> ( ']'
+ >> (+eol | cl::end_p)
+ | cl::eps_p [actions.error]
+ )
             ;
 
         local.doc_attribute =

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:03:25 EST (Thu, 17 Nov 2011)
@@ -86,28 +86,24 @@
 
         cl::parse_info<parse_iterator> info = cl::parse(first, last, actor.grammar().doc_info);
 
- docinfo_types docinfo_type =
- !nested_file ? docinfo_main :
- info.hit && qbk_version_n >= 106 ? docinfo_nested :
- docinfo_ignore;
-
+ // TODO: Fix this:
         if (!info.hit) actor.source_mode = saved_source_mode;
 
- if (info.hit || !docinfo_type)
+ if (!actor.error_count)
         {
- pre(actor.out, actor, include_doc_id, docinfo_type);
+ std::string doc_type = pre(actor.out, actor, include_doc_id, nested_file);
 
             info = cl::parse(info.hit ? info.stop : first, last, actor.grammar().block);
 
- post(actor.out, actor, docinfo_type);
- }
+ post(actor.out, actor, doc_type);
 
- if (!info.full)
- {
- file_position const& pos = get_position(info.stop, actor.current_file->source);
- detail::outerr(actor.current_file->path, pos.line)
- << "Syntax Error near column " << pos.column << ".\n";
- ++actor.error_count;
+ if (!info.full)
+ {
+ file_position const& pos = get_position(info.stop, actor.current_file->source);
+ detail::outerr(actor.current_file->path, pos.line)
+ << "Syntax Error near column " << pos.column << ".\n";
+ ++actor.error_count;
+ }
         }
     }
 


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