Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59560 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-02-07 04:10:59


Author: danieljames
Date: 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
New Revision: 59560
URL: http://svn.boost.org/trac/boost/changeset/59560

Log:
Partially translate doc_info handling to new style.
Added:
   branches/quickbook-1.5-spirit2/doc_info_actions.cpp (contents, props changed)
   branches/quickbook-1.5-spirit2/doc_info_actions.hpp (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 1
   branches/quickbook-1.5-spirit2/actions.cpp | 179 ----------------------------------------
   branches/quickbook-1.5-spirit2/actions.hpp | 45 ---------
   branches/quickbook-1.5-spirit2/boostbook.cpp | 130 ++++++++++++++++++++++++++++
   branches/quickbook-1.5-spirit2/boostbook.hpp | 4
   branches/quickbook-1.5-spirit2/doc_info.hpp | 16 ++
   branches/quickbook-1.5-spirit2/process.cpp | 3
   branches/quickbook-1.5-spirit2/quickbook.cpp | 6
   8 files changed, 156 insertions(+), 228 deletions(-)

Modified: branches/quickbook-1.5-spirit2/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/Jamfile.v2 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -35,6 +35,7 @@
     block_actions.cpp
     block_list.cpp
     doc_info.cpp
+ doc_info_actions.cpp
     code_snippet.cpp
     code_snippet_grammar.cpp
     syntax_highlight.cpp

Modified: branches/quickbook-1.5-spirit2/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/actions.cpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -51,185 +51,6 @@
         detail::outwarn(pos.file,pos.line) << "Empty id.\n";
     }
 
- void xml_author::operator()(std::pair<std::string, std::string> const& author) const
- {
- out << " <author>\n"
- << " <firstname>" << author.first << "</firstname>\n"
- << " <surname>" << author.second << "</surname>\n"
- << " </author>\n";
- }
-
- void xml_copyright::operator()(std::pair<std::vector<std::string>, std::string> const& copyright) const
- {
- out << "\n" << " <copyright>\n";
-
- for_each(
- copyright.first.begin()
- , copyright.first.end()
- , xml_year(out));
-
- out << " <holder>" << copyright.second << "</holder>\n"
- << " </copyright>\n"
- << "\n"
- ;
- }
-
- void xml_year::operator()(std::string const &year) const
- {
- out << " <year>" << year << "</year>\n";
- }
-
- static void write_document_title(collector& out, doc_info& actions);
- static void write_document_info(collector& out, doc_info& actions);
-
- void pre(collector& out, quickbook::actions& actions, doc_info& info, bool ignore_docinfo)
- {
- // The doc_info in the file has been parsed. Here's what we'll do
- // *before* anything else.
-
- if (!info.doc_title.empty())
- actions.doc_title = info.doc_title;
-
- if (info.doc_id.empty())
- info.doc_id = detail::make_identifier(
- actions.doc_title.begin(),actions.doc_title.end());
-
- if(actions.doc_id.empty())
- actions.doc_id = info.doc_id;
-
- if (info.doc_dirname.empty() && info.doc_type == "library")
- info.doc_dirname = actions.doc_id;
-
- if (info.doc_last_revision.empty())
- {
- // default value for last-revision is now
-
- char strdate[64];
- strftime(
- strdate, sizeof(strdate),
- (debug_mode ?
- "DEBUG MODE Date: %Y/%m/%d %H:%M:%S $" :
- "$" /* prevent CVS substitution */ "Date: %Y/%m/%d %H:%M:%S $"),
- current_gm_time
- );
- info.doc_last_revision = strdate;
- }
-
- // if we're ignoring the document info, we're done.
- if (ignore_docinfo)
- {
- return;
- }
-
- out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- << "<!DOCTYPE library PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
- << " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">\n"
- << '<' << info.doc_type << "\n"
- << " id=\"" << info.doc_id << "\"\n";
-
- if(info.doc_type == "library")
- {
- out << " name=\"" << info.doc_title << "\"\n";
- }
-
- if(!info.doc_dirname.empty())
- {
- out << " dirname=\"" << info.doc_dirname << "\"\n";
- }
-
- out << " last-revision=\"" << info.doc_last_revision << "\" \n"
- << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
-
- if(info.doc_type == "library") {
- write_document_info(out, info);
- write_document_title(out, info);
- }
- else {
- write_document_title(out, info);
- write_document_info(out, info);
- }
- }
-
- void post(collector& out, quickbook::actions& actions, doc_info& info, bool ignore_docinfo)
- {
- // if we're ignoring the document info, do nothing.
- if (ignore_docinfo)
- {
- return;
- }
-
- // We've finished generating our output. Here's what we'll do
- // *after* everything else.
- out << "\n</" << info.doc_type << ">\n\n";
- }
-
- void write_document_title(collector& out, doc_info& info)
- {
- if (!info.doc_title.empty())
- {
- out<< " <title>" << info.doc_title;
- if (!info.doc_version.empty())
- out << ' ' << info.doc_version;
- out<< "</title>\n\n\n";
- }
- }
-
- void write_document_info(collector& out, doc_info& info)
- {
- out << " <" << info.doc_type << "info>\n";
-
- if(!info.doc_authors.empty())
- {
- out << " <authorgroup>\n";
- for_each(
- info.doc_authors.begin()
- , info.doc_authors.end()
- , xml_author(out));
- out << " </authorgroup>\n";
- }
-
- if (!info.doc_copyrights.empty())
- {
- for_each(
- info.doc_copyrights.begin()
- , info.doc_copyrights.end()
- , xml_copyright(out));
- }
-
- if (!info.doc_license.empty())
- {
- out << " <legalnotice>\n"
- << " <para>\n"
- << " " << info.doc_license << "\n"
- << " </para>\n"
- << " </legalnotice>\n"
- << "\n"
- ;
- }
-
- if (!info.doc_purpose.empty())
- {
- out << " <" << info.doc_type << "purpose>\n"
- << " " << info.doc_purpose
- << " </" << info.doc_type << "purpose>\n"
- << "\n"
- ;
- }
-
- if (!info.doc_category.empty())
- {
- out << " <" << info.doc_type << "category name=\"category:"
- << info.doc_category
- << "\"></" << info.doc_type << "category>\n"
- << "\n"
- ;
- }
-
- out << " </" << info.doc_type << "info>\n"
- << "\n"
- ;
- }
-
     void phrase_push_action::operator()(unused_type, unused_type, unused_type) const
     {
         phrase.push();

Modified: branches/quickbook-1.5-spirit2/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/actions.hpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -97,47 +97,11 @@
         actions& escape_actions;
     };
 
- struct element_id_warning_action
- {
- void operator()(iterator_range, unused_type, unused_type) const;
- };
-
- struct xml_author
+ struct element_id_warning_action
     {
- // Handles xml author
-
- xml_author(collector& out)
- : out(out) {}
-
- void operator()(std::pair<std::string, std::string> const& author) const;
-
- collector& out;
+ void operator()(iterator_range, unused_type, unused_type) const;
     };
 
- struct xml_year
- {
- // Handles xml year
-
- xml_year(collector& out)
- : out(out) {}
-
- void operator()(std::string const &year) const;
-
- collector& out;
- };
-
- struct xml_copyright
- {
- // Handles xml copyright
-
- xml_copyright(collector& out)
- : out(out) {}
-
- void operator()(std::pair<std::vector<std::string>, std::string> const &copyright) const;
-
- collector& out;
- };
-
     struct phrase_push_action
     {
         phrase_push_action(collector& phrase)
@@ -164,11 +128,6 @@
         collector& phrase;
     };
 
- struct doc_info;
-
- void pre(collector& out, quickbook::actions& actions, doc_info& info, bool ignore_docinfo = false);
- void post(collector& out, quickbook::actions& actions, doc_info& info, bool ignore_docinfo = false);
-
     struct process_action
     {
         process_action(quickbook::actions& actions)

Modified: branches/quickbook-1.5-spirit2/boostbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/boostbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/boostbook.cpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -1,8 +1,9 @@
+#include <algorithm>
+#include <boost/foreach.hpp>
 #include "fwd.hpp"
 #include "boostbook.hpp"
 #include "phrase.hpp"
 #include "actions_class.hpp"
-#include <algorithm>
 
 namespace quickbook
 {
@@ -344,4 +345,131 @@
                 << "</phrase>";
         }
     }
+
+ void output(quickbook::actions& actions, doc_info const& info)
+ {
+ // if we're ignoring the document info, we're done.
+ if (info.ignore) return;
+
+ actions.phrase
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<!DOCTYPE library PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\""
+ << " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">";
+
+ // Document tag
+
+ actions.phrase
+ << '<' << info.doc_type << " id=\"" << info.doc_id << "\"\n";
+
+ if(info.doc_type == "library")
+ {
+ actions.phrase << " name=\"" << info.doc_title << "\"\n";
+ }
+
+ if(!info.doc_dirname.empty())
+ {
+ actions.phrase << " dirname=\"" << info.doc_dirname << "\"\n";
+ }
+
+ actions.phrase
+ << "last-revision=\"" << info.doc_last_revision << "\""
+ << " xmlns:xi=\"http://www.w3.org/2001/XInclude\"";
+
+ actions.phrase << ">"; // end document tag.
+
+ // Title tag
+
+ std::string title;
+ if(!info.doc_title.empty())
+ {
+ title = "<title>" + info.doc_title;
+ if (!info.doc_version.empty())
+ title += ' ' + info.doc_version;
+ title += "</title>\n";
+ }
+
+ // For 'library', the title comes after the info block.
+ if(info.doc_type != "library") actions.phrase << title;
+
+ // Info tag
+
+ actions.phrase << "<" << info.doc_type << "info>\n";
+
+ if(!info.doc_authors.empty())
+ {
+ actions.phrase << "<authorgroup>\n";
+ BOOST_FOREACH(doc_info::author const& author, info.doc_authors) {
+ actions.phrase
+ << "<author>\n"
+ << "<firstname>" << author.first << "</firstname>\n"
+ << "<surname>" << author.second << "</surname>\n"
+ << "</author>\n";
+ }
+ actions.phrase << "</authorgroup>\n";
+ }
+
+ BOOST_FOREACH(doc_info::copyright_entry const& copyright,
+ info.doc_copyrights)
+ {
+ actions.phrase << "<copyright>\n";
+
+ BOOST_FOREACH(std::string const& year, copyright.first) {
+ actions.phrase << "<year>" << year << "</year>\n";
+ }
+
+ actions.phrase
+ << "<holder>" << copyright.second << "</holder>\n"
+ << "</copyright>\n"
+ ;
+ }
+
+ if (!info.doc_license.empty())
+ {
+ actions.phrase
+ << "<legalnotice>\n"
+ << "<para>\n"
+ << info.doc_license
+ << "\n"
+ << "</para>\n"
+ << "</legalnotice>\n"
+ << "\n"
+ ;
+ }
+
+ if (!info.doc_purpose.empty())
+ {
+ actions.phrase
+ << "<" << info.doc_type << "purpose>\n"
+ << info.doc_purpose
+ << "</" << info.doc_type << "purpose>\n"
+ << "\n"
+ ;
+ }
+
+ if (!info.doc_category.empty())
+ {
+ actions.phrase
+ << "<" << info.doc_type << "category name=\"category:"
+ << info.doc_category
+ << "\"></" << info.doc_type << "category>\n"
+ << "\n"
+ ;
+ }
+
+ actions.phrase
+ << "</" << info.doc_type << "info>\n"
+ ;
+
+ if(info.doc_type == "library") actions.phrase << title;
+ }
+
+ void output(quickbook::actions& actions, doc_info_post const& x)
+ {
+ // if we're ignoring the document info, do nothing.
+ if (x.info.ignore) return;
+
+ // We've finished generating our output. Here's what we'll do
+ // *after* everything else.
+ actions.phrase << "</" << x.info.doc_type << ">";
+ }
 }

Modified: branches/quickbook-1.5-spirit2/boostbook.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/boostbook.hpp (original)
+++ branches/quickbook-1.5-spirit2/boostbook.hpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -16,6 +16,7 @@
 #include "phrase.hpp"
 #include "block.hpp"
 #include "syntax_highlight.hpp"
+#include "doc_info.hpp"
 #include "gen_types.hpp"
 
 namespace quickbook
@@ -28,6 +29,9 @@
     // should either take a stream/collector to write to, or return their
     // output by value.
 
+ void output(quickbook::actions&, doc_info const&);
+ void output(quickbook::actions&, doc_info_post const&);
+
     // Note: char is a plain quickbook character, string is an encoded
     // boostbook string. Oops.
     void output(quickbook::actions&, char);

Modified: branches/quickbook-1.5-spirit2/doc_info.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info.hpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info.hpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -12,14 +12,17 @@
 
 #include <vector>
 #include <string>
+#include <utility>
 
 namespace quickbook
 {
     struct doc_info
     {
- typedef std::vector<std::string> string_list;
- typedef std::vector<std::pair<std::string, std::string> > author_list;
- typedef std::vector<std::pair<string_list, std::string> > copyright_list;
+ typedef std::vector<std::string> copyright_years;
+ typedef std::pair<copyright_years, std::string> copyright_entry;
+ typedef std::vector<copyright_entry> copyright_list;
+ typedef std::pair<std::string, std::string> author;
+ typedef std::vector<author> author_list;
 
         std::string doc_type;
         std::string doc_title;
@@ -32,6 +35,13 @@
         author_list doc_authors;
         std::string doc_license;
         std::string doc_last_revision;
+ bool ignore;
+ };
+
+ struct doc_info_post
+ {
+ doc_info_post(doc_info& info) : info(info) {}
+ doc_info& info;
     };
 }
 

Added: branches/quickbook-1.5-spirit2/doc_info_actions.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/doc_info_actions.cpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -0,0 +1,61 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include <string>
+#include <vector>
+#include <utility>
+#include "fwd.hpp"
+#include "collector.hpp"
+#include "doc_info_actions.hpp"
+#include "actions_class.hpp"
+#include "utils.hpp"
+
+namespace quickbook
+{
+ doc_info process(quickbook::actions& actions, doc_info const& x)
+ {
+ doc_info info = x;
+
+ // The doc_info in the file has been parsed. Here's what we'll do
+ // *before* anything else.
+
+ if(!info.doc_title.empty())
+ actions.state_.doc_title = info.doc_title;
+
+ if(info.doc_id.empty())
+ info.doc_id = detail::make_identifier(
+ actions.state_.doc_title.begin(),
+ actions.state_.doc_title.end());
+
+ if(actions.state_.doc_id.empty())
+ actions.state_.doc_id = info.doc_id;
+
+ if (info.doc_dirname.empty() && info.doc_type == "library")
+ info.doc_dirname = actions.state_.doc_id;
+
+ if (info.doc_last_revision.empty())
+ {
+ // default value for last-revision is now
+
+ char strdate[64];
+ strftime(
+ strdate, sizeof(strdate),
+ (debug_mode ?
+ "DEBUG MODE Date: %Y/%m/%d %H:%M:%S $" :
+ "$" /* prevent CVS substitution */ "Date: %Y/%m/%d %H:%M:%S $"),
+ current_gm_time
+ );
+ info.doc_last_revision = strdate;
+ }
+
+ return info;
+ }
+}

Added: branches/quickbook-1.5-spirit2/doc_info_actions.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/doc_info_actions.hpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -0,0 +1,23 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#if !defined(BOOST_SPIRIT_QUICKBOOK_DOC_INFO_ACTIONS_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_DOC_INFO_ACTIONS_HPP
+
+#include "fwd.hpp"
+#include "doc_info.hpp"
+
+namespace quickbook
+{
+ doc_info process(quickbook::actions&, doc_info const&);
+}
+
+#endif

Modified: branches/quickbook-1.5-spirit2/process.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/process.cpp (original)
+++ branches/quickbook-1.5-spirit2/process.cpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -17,6 +17,7 @@
 #include "code.hpp"
 #include "syntax_highlight.hpp"
 #include "template.hpp"
+#include "doc_info_actions.hpp"
 #include "boostbook.hpp"
 
 namespace quickbook
@@ -64,4 +65,6 @@
     template void process_action::operator()<define_template>(define_template const&) const;
     template void process_action::operator()<code_token>(code_token const&) const;
     template void process_action::operator()<char>(char const&) const;
+ template void process_action::operator()<doc_info>(doc_info const&) const;
+ template void process_action::operator()<doc_info_post>(doc_info_post const&) const;
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/quickbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/quickbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/quickbook.cpp 2010-02-07 04:10:55 EST (Sun, 07 Feb 2010)
@@ -71,13 +71,15 @@
         {
             if(!success) first = start;
 
- pre(actor.phrase, actor, info, ignore_docinfo);
+ info.ignore = ignore_docinfo;
+
+ actor.process(info);
 
             block_grammar g(actor);
             success = parse(first, last, g);
             if (success && first == last)
             {
- post(actor.phrase, actor, info, ignore_docinfo);
+ actor.process(doc_info_post(info));
             }
         }
         else {


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