Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62848 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-12 09:06:00


Author: danieljames
Date: 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
New Revision: 62848
URL: http://svn.boost.org/trac/boost/changeset/62848

Log:
Go back to using separate collectors for blocks and phrases.
Text files modified:
   branches/quickbook-1.5-spirit2/actions.cpp | 2
   branches/quickbook-1.5-spirit2/actions.hpp | 2
   branches/quickbook-1.5-spirit2/block.hpp | 11 ++
   branches/quickbook-1.5-spirit2/block_actions.cpp | 4
   branches/quickbook-1.5-spirit2/block_actions.hpp | 2
   branches/quickbook-1.5-spirit2/block_grammar.cpp | 4
   branches/quickbook-1.5-spirit2/block_markup_grammar.cpp | 13 +--
   branches/quickbook-1.5-spirit2/block_table_grammar.cpp | 27 +++----
   branches/quickbook-1.5-spirit2/boostbook.cpp | 135 ++++++++++++++++++++-------------------
   branches/quickbook-1.5-spirit2/code.hpp | 3
   branches/quickbook-1.5-spirit2/encoder.hpp | 3
   branches/quickbook-1.5-spirit2/encoder_impl.hpp | 2
   branches/quickbook-1.5-spirit2/html.cpp | 127 +++++++++++++++++++-----------------
   branches/quickbook-1.5-spirit2/phrase_actions.cpp | 24 ++++--
   branches/quickbook-1.5-spirit2/phrase_actions.hpp | 3
   branches/quickbook-1.5-spirit2/phrase_grammar.cpp | 6
   branches/quickbook-1.5-spirit2/process.cpp | 20 +++++
   branches/quickbook-1.5-spirit2/state.cpp | 5 +
   branches/quickbook-1.5-spirit2/state.hpp | 1
   branches/quickbook-1.5-spirit2/template.cpp | 4
   20 files changed, 227 insertions(+), 171 deletions(-)

Modified: branches/quickbook-1.5-spirit2/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/actions.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -29,6 +29,8 @@
         , process(*this)
         , phrase_push(state.phrase)
         , phrase_pop(state.phrase)
+ , block_push(state.block)
+ , block_pop(state.block)
         , error(state.error_count)
     {}
 

Modified: branches/quickbook-1.5-spirit2/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/actions.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -169,6 +169,8 @@
         process_action process;
         phrase_push_action phrase_push;
         phrase_pop_action phrase_pop;
+ phrase_push_action block_push;
+ phrase_pop_action block_pop;
         error_action error;
         element_id_warning_action element_id_warning;
     };

Modified: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.hpp (original)
+++ branches/quickbook-1.5-spirit2/block.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -19,6 +19,11 @@
 
 namespace quickbook
 {
+ struct block_formatted {
+ formatted_type type;
+ std::string content;
+ };
+
     struct hr
     {
     };
@@ -27,7 +32,7 @@
     {
         std::string content;
     };
-
+
     struct list_item
     {
         file_position position;
@@ -67,7 +72,7 @@
         std::string content;
     };
 
- typedef std::vector<quickbook::formatted> varlistentry;
+ typedef std::vector<quickbook::block_formatted> varlistentry;
 
     struct variablelist
     {
@@ -75,7 +80,7 @@
         std::vector<varlistentry> entries;
     };
 
- typedef quickbook::formatted table_cell;
+ typedef quickbook::block_formatted table_cell;
     typedef std::vector<table_cell> table_row;
     
     struct table

Modified: branches/quickbook-1.5-spirit2/block_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -36,9 +36,9 @@
         }
     }
 
- formatted process(quickbook::state& state, paragraph const& x)
+ block_formatted process(quickbook::state& state, paragraph const& x)
     {
- formatted r;
+ block_formatted r;
         r.type="paragraph";
         r.content = x.content;
         return r;

Modified: branches/quickbook-1.5-spirit2/block_actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -16,7 +16,7 @@
 namespace quickbook
 {
     // TODO: Just generate formatted.
- formatted process(quickbook::state&, paragraph const&);
+ block_formatted process(quickbook::state&, paragraph const&);
     begin_section2 process(quickbook::state&, begin_section const&);
     end_section2 process(quickbook::state&, end_section const&);
     heading2 process(quickbook::state&, heading const&);

Modified: branches/quickbook-1.5-spirit2/block_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_grammar.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -75,7 +75,7 @@
 
         code =
                 position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::block, true)]
+ [member_assign(&quickbook::code::flow, quickbook::code::block)]
>> qi::raw[code_line >> *(*eol >> code_line)]
                                                         [member_assign(&quickbook::code::content)]
>> +eol
@@ -140,7 +140,7 @@
                     ) [actions.process]
                 )
>> qi::eps [actions.phrase_pop]
- >> (&qi::lit('[') | +eol)
+ >> (&qi::lit('[') | +eol)
             ;
 
         paragraph_end =

Modified: branches/quickbook-1.5-spirit2/block_markup_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_markup_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_markup_grammar.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -17,7 +17,6 @@
 #include "grammar_impl.hpp"
 #include "block.hpp"
 #include "actions.hpp"
-#include "code.hpp"
 #include "misc_rules.hpp"
 #include "parse_utils.hpp"
 
@@ -37,7 +36,7 @@
     {
         // Paragraph Blocks
 
- qi::rule<iterator, quickbook::formatted(formatted_type)>& paragraph_block = store_.create();
+ qi::rule<iterator, quickbook::block_formatted(formatted_type)>& paragraph_block = store_.create();
 
         block_keyword_rules.add
             ("blurb", paragraph_block(formatted_type("blurb")) [actions.process])
@@ -53,22 +52,22 @@
             ;
 
         paragraph_block =
- qi::attr(qi::_r1) [member_assign(&quickbook::formatted::type)]
+ qi::attr(qi::_r1) [member_assign(&quickbook::block_formatted::type)]
>> space
- >> inside_paragraph [member_assign(&quickbook::formatted::content)]
+ >> inside_paragraph [member_assign(&quickbook::block_formatted::content)]
             ;
 
         // Preformatted
 
- qi::rule<iterator, quickbook::formatted()>& preformatted = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& preformatted = store_.create();
 
         block_keyword_rules.add("pre", preformatted [actions.process]);
         
         preformatted =
                 space [ph::ref(no_eols) = false]
- [member_assign(&quickbook::formatted::type, "preformatted")]
+ [member_assign(&quickbook::block_formatted::type, "preformatted")]
>> -eol
- >> phrase_attr [member_assign(&quickbook::formatted::content)]
+ >> phrase_attr [member_assign(&quickbook::block_formatted::content)]
>> qi::eps [ph::ref(no_eols) = true]
             ;
 

Modified: branches/quickbook-1.5-spirit2/block_table_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_table_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_table_grammar.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -17,7 +17,6 @@
 #include "grammar_impl.hpp"
 #include "block.hpp"
 #include "actions.hpp"
-#include "code.hpp"
 #include "misc_rules.hpp"
 #include "parse_utils.hpp"
 
@@ -40,7 +39,7 @@
         qi::rule<iterator, quickbook::table()>& table = store_.create();
         qi::rule<iterator, quickbook::table_row()>& table_row = store_.create();
         qi::rule<iterator, quickbook::table_cell()>& table_cell = store_.create();
- qi::rule<iterator, quickbook::formatted()>& table_cell_body = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& table_cell_body = store_.create();
         
         block_keyword_rules.add("table", table[actions.process]);
 
@@ -73,16 +72,16 @@
             ;
 
         table_cell_body =
- inside_paragraph [member_assign(&quickbook::formatted::content)]
- [member_assign(&quickbook::formatted::type, "cell")]
+ inside_paragraph [member_assign(&quickbook::block_formatted::content)]
+ [member_assign(&quickbook::block_formatted::type, "cell")]
             ;
 
         qi::rule<iterator, quickbook::variablelist()>& variablelist = store_.create();
         qi::rule<iterator, quickbook::varlistentry()>& varlistentry = store_.create();
- qi::rule<iterator, quickbook::formatted()>& varlistterm = store_.create();
- qi::rule<iterator, quickbook::formatted()>& varlistterm_body = store_.create();
- qi::rule<iterator, quickbook::formatted()>& varlistitem = store_.create();
- qi::rule<iterator, quickbook::formatted()>& varlistitem_body = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& varlistterm = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& varlistterm_body = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& varlistitem = store_.create();
+ qi::rule<iterator, quickbook::block_formatted()>& varlistitem_body = store_.create();
         
         block_keyword_rules.add("variablelist", variablelist[actions.process]);
 
@@ -108,26 +107,26 @@
                 space
>> '['
>> ( varlistterm_body >> ']' >> space
- | error >> qi::attr(quickbook::formatted())
+ | error >> qi::attr(quickbook::block_formatted())
                 )
             ;
 
         varlistterm_body =
- phrase_attr [member_assign(&quickbook::formatted::content)]
- [member_assign(&quickbook::formatted::type, "varlistterm")]
+ phrase_attr [member_assign(&quickbook::block_formatted::content)]
+ [member_assign(&quickbook::block_formatted::type, "varlistterm")]
             ;
 
         varlistitem =
                 space
>> '['
>> ( varlistitem_body >> ']' >> space
- | error >> qi::attr(quickbook::formatted())
+ | error >> qi::attr(quickbook::block_formatted())
                 )
             ;
 
         varlistitem_body =
- inside_paragraph [member_assign(&quickbook::formatted::content)]
- [member_assign(&quickbook::formatted::type, "varlistitem")]
+ inside_paragraph [member_assign(&quickbook::block_formatted::content)]
+ [member_assign(&quickbook::block_formatted::type, "varlistitem")]
             ;
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/boostbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/boostbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/boostbook.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -54,7 +54,6 @@
     
         boostbook_markup markups[] = {
             { "", "", "" },
- { "comment", "<!--", "-->" },
             { "paragraph", "<para>\n", "</para>\n" },
             { "h1", "<bridgehead renderas=\"sect1\">", "</bridgehead>" },
             { "h2", "<bridgehead renderas=\"sect2\">", "</bridgehead>" },
@@ -173,6 +172,12 @@
         state.phrase << m.pre << x.content << m.post;
     }
 
+ void boostbook_encoder::operator()(quickbook::state& state, block_formatted const& x)
+ {
+ boostbook_markup m = get_markup(x.type);
+ state.block << m.pre << x.content << m.post;
+ }
+
     void boostbook_encoder::operator()(quickbook::state& state, break_ const& x)
     {
         boostbook_markup m = get_markup("break");
@@ -215,21 +220,21 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, hr)
     {
- state.phrase << get_markup("hr").pre;
+ state.block << get_markup("hr").pre;
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, begin_section2 const& x)
     {
- state.phrase << "\n<section id=\"" << encode(x.id) << "\">\n";
+ state.block << "\n<section id=\"" << encode(x.id) << "\">\n";
         if(x.linkend.empty()) {
- state.phrase
+ state.block
                 << "<title>"
                 << x.content
                 << "</title>\n"
                 ;
         }
         else {
- state.phrase
+ state.block
                 << "<title>"
                 << "<link linkend=\""
                 << encode(x.linkend)
@@ -243,123 +248,123 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, end_section2 const& x)
     {
- state.phrase << "</section>";
+ state.block << "</section>";
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, heading2 const& x)
     {
- state.phrase
+ state.block
             << "<anchor id=\"" << encode(x.id) << "\"/>"
             << "<bridgehead renderas=\"sect" << x.level << "\">";
 
         if(x.linkend.empty()) {
- state.phrase << x.content;
+ state.block << x.content;
         }
         else {
- state.phrase
+ state.block
                 << "<link linkend=\"" << encode(x.linkend) << "\">"
                 << x.content << "</link>";
         }
 
- state.phrase << "</bridgehead>";
+ state.block << "</bridgehead>";
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, variablelist const& x)
     {
- state.phrase << "<variablelist>\n";
+ state.block << "<variablelist>\n";
 
- state.phrase << "<title>";
- state.phrase << encode(x.title);
- state.phrase << "</title>\n";
+ state.block << "<title>";
+ state.block << encode(x.title);
+ state.block << "</title>\n";
 
         boostbook_markup m = get_markup("varlistentry");
 
         for(std::vector<varlistentry>::const_iterator
             it = x.entries.begin(); it != x.entries.end(); ++it)
         {
- state.phrase << m.pre;
+ state.block << m.pre;
             std::for_each(it->begin(), it->end(), encode_action(state, *this));
- state.phrase << m.post;
+ state.block << m.post;
         }
 
- state.phrase << "</variablelist>\n";
+ state.block << "</variablelist>\n";
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, table2 const& x)
     {
         if (x.title)
         {
- state.phrase << "<table frame=\"all\"";
+ state.block << "<table frame=\"all\"";
             if(x.id)
- state.phrase << " id=\"" << encode(*x.id) << "\"";
- state.phrase << ">\n";
- state.phrase << "<title>";
- state.phrase << encode(*x.title);
- state.phrase << "</title>";
+ state.block << " id=\"" << encode(*x.id) << "\"";
+ state.block << ">\n";
+ state.block << "<title>";
+ state.block << encode(*x.title);
+ state.block << "</title>";
         }
         else
         {
- state.phrase << "<informaltable frame=\"all\"";
+ state.block << "<informaltable frame=\"all\"";
             if(x.id)
- state.phrase << " id=\"" << encode(*x.id) << "\"";
- state.phrase << ">\n";
+ state.block << " id=\"" << encode(*x.id) << "\"";
+ state.block << ">\n";
         }
 
         // This is a bit odd for backwards compatability: the old version just
         // used the last count that was calculated.
- state.phrase << "<tgroup cols=\"" << x.cols << "\">\n";
+ state.block << "<tgroup cols=\"" << x.cols << "\">\n";
 
         boostbook_markup m = get_markup("row");
 
         if (x.head)
         {
- state.phrase << "<thead>";
- state.phrase << m.pre;
+ state.block << "<thead>";
+ state.block << m.pre;
             std::for_each(x.head->begin(), x.head->end(), encode_action(state, *this));
- state.phrase << m.post;
- state.phrase << "</thead>\n";
+ state.block << m.post;
+ state.block << "</thead>\n";
         }
 
- state.phrase << "<tbody>\n";
+ state.block << "<tbody>\n";
 
         for(std::vector<table_row>::const_iterator
             it = x.rows.begin(); it != x.rows.end(); ++it)
         {
- state.phrase << m.pre;
+ state.block << m.pre;
             std::for_each(it->begin(), it->end(), encode_action(state, *this));
- state.phrase << m.post;
+ state.block << m.post;
         }
 
- state.phrase << "</tbody>\n" << "</tgroup>\n";
+ state.block << "</tbody>\n" << "</tgroup>\n";
 
         if (x.title)
         {
- state.phrase << "</table>\n";
+ state.block << "</table>\n";
         }
         else
         {
- state.phrase << "</informaltable>\n";
+ state.block << "</informaltable>\n";
         }
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, xinclude2 const& x)
     {
- state.phrase << "\n<xi:include href=\"" << x.path << "\" />\n";
+ state.block << "\n<xi:include href=\"" << x.path << "\" />\n";
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, list2 const& x)
     {
- state.phrase << std::string(x.mark == '#' ? "<orderedlist>\n" : "<itemizedlist>\n");
+ state.block << std::string(x.mark == '#' ? "<orderedlist>\n" : "<itemizedlist>\n");
 
         for(std::vector<list_item2>::const_iterator
             it = x.items.begin(), end = x.items.end(); it != end; ++it)
         {
- state.phrase << "<listitem><simpara>\n" << it->content;
+ state.block << "<listitem><simpara>\n" << it->content;
             if(!it->sublist.items.empty()) (*this)(state, it->sublist);
- state.phrase << std::string("\n</simpara></listitem>");
+ state.block << std::string("\n</simpara></listitem>");
         }
 
- state.phrase << std::string(x.mark == '#' ? "\n</orderedlist>" : "\n</itemizedlist>");
+ state.block << std::string(x.mark == '#' ? "\n</orderedlist>" : "\n</itemizedlist>");
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, callout_link const& x)
@@ -373,12 +378,12 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, callout_list const& x)
     {
- state.phrase
+ state.block
             << "<calloutlist>";
 
         BOOST_FOREACH(callout_item const& c, x)
         {
- state.phrase
+ state.block
                 << "<callout arearefs=\"" << c.identifier << "co\""
                 << " id=\"" << c.identifier << "\""
                 << ">"
@@ -386,7 +391,7 @@
                 << "</callout>";
         }
 
- state.phrase
+ state.block
             << "</calloutlist>";
     }
 
@@ -409,7 +414,7 @@
         // if we're ignoring the document info, we're done.
         if (info.ignore) return;
 
- state.phrase
+ state.block
             << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
             << "<!DOCTYPE "
             << info.doc_type
@@ -418,24 +423,24 @@
 
         // Document tag
 
- state.phrase
+ state.block
             << '<' << info.doc_type << " id=\"" << encode(info.doc_id) << "\"\n";
         
         if(info.doc_type == "library")
         {
- state.phrase << " name=\"" << encode(info.doc_title) << "\"\n";
+ state.block << " name=\"" << encode(info.doc_title) << "\"\n";
         }
 
         if(!info.doc_dirname.empty())
         {
- state.phrase << " dirname=\"" << encode(info.doc_dirname) << "\"\n";
+ state.block << " dirname=\"" << encode(info.doc_dirname) << "\"\n";
         }
 
- state.phrase
+ state.block
             << "last-revision=\"" << encode(info.doc_last_revision) << "\""
             << " xmlns:xi=\"http://www.w3.org/2001/XInclude\"";
 
- state.phrase << ">"; // end document tag.
+ state.block << ">"; // end document tag.
 
         // Title tag
 
@@ -449,35 +454,35 @@
         }
 
         // For 'library', the title comes after the info block.
- if(info.doc_type != "library") state.phrase << title;
+ if(info.doc_type != "library") state.block << title;
 
         // Info tag
 
- state.phrase << "<" << info.doc_type << "info>\n";
+ state.block << "<" << info.doc_type << "info>\n";
 
         if(!info.doc_authors.empty())
         {
- state.phrase << "<authorgroup>\n";
+ state.block << "<authorgroup>\n";
             BOOST_FOREACH(doc_info::author const& author, info.doc_authors) {
- state.phrase
+ state.block
                     << "<author>\n"
                     << "<firstname>" << author.firstname << "</firstname>\n"
                     << "<surname>" << author.surname << "</surname>\n"
                     << "</author>\n";
             }
- state.phrase << "</authorgroup>\n";
+ state.block << "</authorgroup>\n";
         }
 
         BOOST_FOREACH(doc_info::copyright_entry const& copyright,
             info.doc_copyrights)
         {
- state.phrase << "<copyright>\n";
+ state.block << "<copyright>\n";
 
             BOOST_FOREACH(unsigned int year, copyright.years) {
- state.phrase << "<year>" << year << "</year>\n";
+ state.block << "<year>" << year << "</year>\n";
             }
 
- state.phrase
+ state.block
                 << "<holder>" << copyright.holder << "</holder>\n"
                 << "</copyright>\n"
             ;
@@ -485,7 +490,7 @@
 
         if (!boost::apply_visitor(empty_visitor(), info.doc_license))
         {
- state.phrase
+ state.block
                 << "<legalnotice>\n"
                 << "<para>\n"
                 << boost::apply_visitor(encode_raw_visitor(*this), info.doc_license)
@@ -498,7 +503,7 @@
 
         if (!boost::apply_visitor(empty_visitor(), info.doc_purpose))
         {
- state.phrase
+ state.block
                 << "<" << info.doc_type << "purpose>\n"
                 << boost::apply_visitor(encode_raw_visitor(*this), info.doc_purpose)
                 << "</" << info.doc_type << "purpose>\n"
@@ -508,7 +513,7 @@
 
         BOOST_FOREACH(raw_string const& category, info.doc_categories)
         {
- state.phrase
+ state.block
                 << "<" << info.doc_type << "category name=\"category:"
                 << encode(category)
                 << "\"></" << info.doc_type << "category>\n"
@@ -516,11 +521,11 @@
             ;
         }
 
- state.phrase
+ state.block
             << "</" << info.doc_type << "info>\n"
         ;
 
- if(info.doc_type == "library") state.phrase << title;
+ if(info.doc_type == "library") state.block << title;
     }
 
     void boostbook_encoder::operator()(quickbook::state& state, doc_info_post const& x)
@@ -530,6 +535,6 @@
 
         // We've finished generating our output. Here's what we'll do
         // *after* everything else.
- state.phrase << "</" << x.info.doc_type << ">";
+ state.block << "</" << x.info.doc_type << ">";
     }
 }

Modified: branches/quickbook-1.5-spirit2/code.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code.hpp (original)
+++ branches/quickbook-1.5-spirit2/code.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -16,7 +16,8 @@
 namespace quickbook
 {
     struct code {
- bool block;
+ enum flow_types { block, inline_block, inline_ };
+ flow_types flow;
         file_position position;
         std::string content;
     };

Modified: branches/quickbook-1.5-spirit2/encoder.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -46,6 +46,7 @@
         virtual void operator()(quickbook::state&, anchor const&) = 0;
         virtual void operator()(quickbook::state&, link const&) = 0;
         virtual void operator()(quickbook::state&, formatted const&) = 0;
+ virtual void operator()(quickbook::state&, block_formatted const&) = 0;
         virtual void operator()(quickbook::state&, break_ const&) = 0;
         virtual void operator()(quickbook::state&, image2 const&) = 0;
     
@@ -70,6 +71,8 @@
 
     struct encode_action
     {
+ typedef void result_type;
+
         encode_action(quickbook::state& state,
             quickbook::encoder& encoder)
             : state(state), encoder(encoder) {}

Modified: branches/quickbook-1.5-spirit2/encoder_impl.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder_impl.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder_impl.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -30,6 +30,7 @@
         virtual void operator()(quickbook::state&, anchor const&);
         virtual void operator()(quickbook::state&, link const&);
         virtual void operator()(quickbook::state&, formatted const&);
+ virtual void operator()(quickbook::state&, block_formatted const&);
         virtual void operator()(quickbook::state&, break_ const&);
         virtual void operator()(quickbook::state&, image2 const&);
     
@@ -67,6 +68,7 @@
         virtual void operator()(quickbook::state&, anchor const&);
         virtual void operator()(quickbook::state&, link const&);
         virtual void operator()(quickbook::state&, formatted const&);
+ virtual void operator()(quickbook::state&, block_formatted const&);
         virtual void operator()(quickbook::state&, break_ const&);
         virtual void operator()(quickbook::state&, image2 const&);
     

Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -54,11 +54,11 @@
             char const* quickbook;
             char const* pre;
             char const* post;
+ bool block;
         };
     
         html_markup markups[] = {
             { "", "", "" },
- { "comment", "<!--", "-->" },
             { "paragraph", "<p>\n", "</p>\n" },
             { "blurb", "<div class=\"blurb\">\n", "</div>\n" },
             { "blockquote", "<blockquote>", "</blockquote>" },
@@ -191,6 +191,13 @@
         }
     }
 
+ void html_encoder::operator()(quickbook::state& state, block_formatted const& x)
+ {
+ std::string type = x.type;
+ html_markup m = get_markup(x.type);
+ state.block << m.pre << x.content << m.post;
+ }
+
     void html_encoder::operator()(quickbook::state& state, break_ const& x)
     {
         html_markup m = get_markup("break");
@@ -227,7 +234,7 @@
 
     void html_encoder::operator()(quickbook::state& state, hr)
     {
- state.phrase << get_markup("hr").pre;
+ state.block << get_markup("hr").pre;
     }
 
     void html_encoder::operator()(quickbook::state& state, begin_section2 const& x)
@@ -236,16 +243,16 @@
         int level = state.section_level + 1;
         if (level > 6) level = 6;
     
- state.phrase << "\n<section id=\"" << encode(x.id) << "\">\n";
+ state.block << "\n<section id=\"" << encode(x.id) << "\">\n";
         if(x.linkend.empty()) {
- state.phrase
+ state.block
                 << "<h" << level << ">"
                 << x.content
                 << "</h" << level << ">\n"
                 ;
         }
         else {
- state.phrase
+ state.block
                 << "<h" << level << " id=\""
                 << encode(x.linkend)
                 << "\">"
@@ -261,91 +268,91 @@
     {
         pop_footnotes(state);
 
- state.phrase << "</section>";
+ state.block << "</section>";
     }
 
     void html_encoder::operator()(quickbook::state& state, heading2 const& x)
     {
- state.phrase
+ state.block
             << "<h" << x.level << " id=\"" << encode(x.id) << "\">"
             ;
 
         if(!x.linkend.empty()) {
- state.phrase
+ state.block
                 << "<a id=\"" << encode(x.linkend) << "\"></a>"
                 ;
         }
- state.phrase << x.content;
+ state.block << x.content;
 
- state.phrase << "</h" << x.level << ">";
+ state.block << "</h" << x.level << ">";
     }
 
     void html_encoder::operator()(quickbook::state& state, variablelist const& x)
     {
         // TODO: What should I do for the title?
- state.phrase << "<p>";
- state.phrase << encode(x.title);
- state.phrase << "</p>\n";
+ state.block << "<p>";
+ state.block << encode(x.title);
+ state.block << "</p>\n";
 
- state.phrase << "<dl>\n";
+ state.block << "<dl>\n";
 
         html_markup m = get_markup("varlistentry");
 
         for(std::vector<varlistentry>::const_iterator
             it = x.entries.begin(); it != x.entries.end(); ++it)
         {
- state.phrase << m.pre;
+ state.block << m.pre;
             std::for_each(it->begin(), it->end(), encode_action(state, *this));
- state.phrase << m.post;
+ state.block << m.post;
         }
 
- state.phrase << "</dl>\n";
+ state.block << "</dl>\n";
     }
 
     void html_encoder::operator()(quickbook::state& state, table2 const& x)
     {
         if (x.title)
         {
- state.phrase << "<table";
+ state.block << "<table";
             if(x.id)
- state.phrase << " id=\"" << encode(*x.id) << "\"";
- state.phrase << ">\n";
- state.phrase << "<caption>";
- state.phrase << encode(*x.title);
- state.phrase << "</caption>";
+ state.block << " id=\"" << encode(*x.id) << "\"";
+ state.block << ">\n";
+ state.block << "<caption>";
+ state.block << encode(*x.title);
+ state.block << "</caption>";
         }
         else
         {
- state.phrase << "<table";
+ state.block << "<table";
             if(x.id)
- state.phrase << " id=\"" << encode(*x.id) << "\"";
- state.phrase << ">\n";
+ state.block << " id=\"" << encode(*x.id) << "\"";
+ state.block << ">\n";
         }
 
         html_markup m = get_markup("row");
 
         if (x.head)
         {
- state.phrase << "<thead>";
- state.phrase << m.pre;
+ state.block << "<thead>";
+ state.block << m.pre;
             std::for_each(x.head->begin(), x.head->end(), encode_action(state, *this));
- state.phrase << m.post;
- state.phrase << "</thead>\n";
+ state.block << m.post;
+ state.block << "</thead>\n";
         }
 
- state.phrase << "<tbody>\n";
+ state.block << "<tbody>\n";
 
         for(std::vector<table_row>::const_iterator
             it = x.rows.begin(); it != x.rows.end(); ++it)
         {
- state.phrase << m.pre;
+ state.block << m.pre;
             std::for_each(it->begin(), it->end(), encode_action(state, *this));
- state.phrase << m.post;
+ state.block << m.post;
         }
 
- state.phrase << "</tbody>\n";
+ state.block << "</tbody>\n";
 
- state.phrase << "</table>\n";
+ state.block << "</table>\n";
     }
 
     void html_encoder::operator()(quickbook::state& state, xinclude2 const& x)
@@ -356,17 +363,17 @@
 
     void html_encoder::operator()(quickbook::state& state, list2 const& x)
     {
- state.phrase << std::string(x.mark == '#' ? "<ol>\n" : "<ul>\n");
+ state.block << std::string(x.mark == '#' ? "<ol>\n" : "<ul>\n");
 
         for(std::vector<list_item2>::const_iterator
             it = x.items.begin(), end = x.items.end(); it != end; ++it)
         {
- state.phrase << "<li>\n" << it->content;
+ state.block << "<li>\n" << it->content;
             if(!it->sublist.items.empty()) (*this)(state, it->sublist);
- state.phrase << std::string("\n</li>");
+ state.block << std::string("\n</li>");
         }
 
- state.phrase << std::string(x.mark == '#' ? "\n</ol>" : "\n</ul>");
+ state.block << std::string(x.mark == '#' ? "\n</ol>" : "\n</ul>");
     }
 
     void html_encoder::operator()(quickbook::state& state, callout_link const& x)
@@ -387,13 +394,13 @@
 
     void html_encoder::operator()(quickbook::state& state, callout_list const& x)
     {
- state.phrase
+ state.block
             << "<dl class=\"calloutlist\">";
         unsigned int count = 0;
 
         BOOST_FOREACH(callout_item const& c, x)
         {
- state.phrase
+ state.block
                 << "<dt id=\"" << c.identifier << "\">"
                 << "<a href=\"#" << c.identifier << "co\">"
                 << "callout " << ++count
@@ -405,7 +412,7 @@
                 ;
         }
 
- state.phrase
+ state.block
             << "</ol>";
     }
 
@@ -428,7 +435,7 @@
         // if we're ignoring the document info, we're done.
         if (info.ignore) return;
 
- state.phrase
+ state.block
             << "<!DOCTYPE html>"
             << "<html><head>"
             << "<title>" << encode(info.doc_title) << "</title>"
@@ -443,18 +450,18 @@
             !boost::apply_visitor(empty_visitor(), info.doc_license))
         {
 
- state.phrase << "<dl>\n";
+ state.block << "<dl>\n";
 
             if(!info.doc_authors.empty())
             {
- state.phrase
+ state.block
                     << "<dt>"
                     << (info.doc_authors.size() == 1 ? "Author:" : "Authors:")
                     << "</dt>\n"
                     ;
 
                 BOOST_FOREACH(doc_info::author const& author, info.doc_authors) {
- state.phrase
+ state.block
                         << "<dd>"
                         << author.firstname
                         << " "
@@ -465,21 +472,21 @@
     
             if(!info.doc_copyrights.empty())
             {
- state.phrase
+ state.block
                     << "<dt>Copyright:</dt>\n"
                     ;
     
                 BOOST_FOREACH(doc_info::copyright_entry const& copyright,
                     info.doc_copyrights)
                 {
- state.phrase << "<dd>&copy; ";
+ state.block << "<dd>&copy; ";
         
                     unsigned int range_state = 0;
                     unsigned int previous = 0;
                     BOOST_FOREACH(unsigned int year, copyright.years) {
                         switch(range_state) {
                         case 0: // Start
- state.phrase << year;
+ state.block << year;
                             range_state = 1;
                             break;
                         case 1: // Printed a year in last iteration
@@ -487,22 +494,22 @@
                                 range_state = 2;
                             }
                             else {
- state.phrase << ", " << year;
+ state.block << ", " << year;
                                 range_state = 1;
                             }
                             break;
                         case 2: // In the middle of a range
                             if(year != previous + 1) {
- state.phrase << " - " << previous << ", " << year;
+ state.block << " - " << previous << ", " << year;
                                 range_state = 1;
                             }
                             break;
                         }
                         previous = year;
                     }
- if(range_state == 2) state.phrase << " - " << previous;
+ if(range_state == 2) state.block << " - " << previous;
         
- state.phrase
+ state.block
                         << " "
                         << copyright.holder
                         << "</dd>\n"
@@ -512,7 +519,7 @@
     
             if (!boost::apply_visitor(empty_visitor(), info.doc_license))
             {
- state.phrase
+ state.block
                     << "<dt>License:</dt>\n"
                     << "<dd>"
                     << boost::apply_visitor(encode_raw_visitor(*this), info.doc_license)
@@ -520,10 +527,10 @@
                 ;
             }
 
- state.phrase << "</dl>\n";
+ state.block << "</dl>\n";
         }
 
- state.phrase
+ state.block
             << "</header>\n"
             ;
 
@@ -539,7 +546,7 @@
 
         // We've finished generating our output. Here's what we'll do
         // *after* everything else.
- state.phrase << "</html>";
+ state.block << "</html>";
     }
 
     void html_encoder::push_footnotes(quickbook::state& state)
@@ -554,11 +561,11 @@
         footnote_stack.pop();
         
         if(!notes.empty()) {
- state.phrase
+ state.block
                 << "<dl class=\"footnotes\">\n";
             
             BOOST_FOREACH(footnote const& x, notes) {
- state.phrase
+ state.block
                     << "<dt id=\"footnote_" << encode(x.id) << "\">"
                     << "<a href=\"#footnote_ref_" << encode(x.id) << "\">"
                     << "Footnote"
@@ -570,7 +577,7 @@
                     ;
             }
 
- state.phrase
+ state.block
                 << "</dl>\n";
         }
     }

Modified: branches/quickbook-1.5-spirit2/phrase_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_actions.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -81,15 +81,14 @@
         return x;
     }
 
- formatted process(quickbook::state& state, code const& x) {
- formatted r;
- r.type = "";
-
+ boost::variant<formatted, block_formatted> process(quickbook::state& state, code const& x) {
          std::string program = x.content;
     
- if(x.block) {
+ if(x.flow == x.block || x.flow == x.inline_block) {
             // preprocess the code section to remove the initial indentation
             detail::unindent(program);
+ formatted r;
+ r.type = "";
             if (program.size() == 0)
                 return r; // Nothing left to do here. The program is empty.
         }
@@ -109,8 +108,17 @@
 
         state.phrase.swap(save);
         
- r.type = x.block ? "programlisting" : "code";
- r.content = str;
- return r;
+ if(x.flow == x.block) {
+ block_formatted r;
+ r.type = "programlisting";
+ r.content = str;
+ return r;
+ }
+ else {
+ formatted r;
+ r.type = x.flow == x.inline_block ? "programlisting" : "code";
+ r.content = str;
+ return r;
+ }
     }
 }

Modified: branches/quickbook-1.5-spirit2/phrase_actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_actions.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -10,6 +10,7 @@
 #if !defined(BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP)
 #define BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP
 
+#include <boost/variant/variant.hpp>
 #include "phrase.hpp"
 #include "code.hpp"
 #include "gen_types.hpp"
@@ -22,7 +23,7 @@
     formatted process(quickbook::state&, simple_markup const&);
     std::string process(quickbook::state&, cond_phrase const&);
     break_ process(quickbook::state&, break_ const&);
- formatted process(quickbook::state&, code const&);
+ boost::variant<formatted, block_formatted> process(quickbook::state&, code const&);
     image2 process(quickbook::state&, image const&);
     std::string process(quickbook::state&, call_template const&);
 }

Modified: branches/quickbook-1.5-spirit2/phrase_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_grammar.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -146,14 +146,14 @@
                 (
                     "```"
>> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::block, true)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
>> code_block1 [member_assign(&quickbook::code::content)]
>> "```"
                 )
             | (
                     "``"
>> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::block, true)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
>> code_block2 [member_assign(&quickbook::code::content)]
>> "``"
                 )
@@ -165,7 +165,7 @@
         inline_code =
                 '`'
>> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::block, false)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_)]
>> inline_code_block [member_assign(&quickbook::code::content)]
>> '`'
             ;

Modified: branches/quickbook-1.5-spirit2/process.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/process.cpp (original)
+++ branches/quickbook-1.5-spirit2/process.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -20,13 +20,29 @@
 #include "template.hpp"
 #include "doc_info_actions.hpp"
 #include "encoder.hpp"
+#include <boost/variant/apply_visitor.hpp>
 
 namespace quickbook
 {
+ namespace {
+ template <typename T>
+ inline void encode_impl(state& state_, T const& x)
+ {
+ (*state_.encoder)(state_, x);
+ }
+
+ template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+ inline void encode_impl(state& state_, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& x)
+ {
+ encode_action visitor(state_, *state_.encoder);
+ boost::apply_visitor(visitor, x);
+ }
+ }
+
     template <typename T>
     void process_action::operator()(T const& x) const
     {
- (*actions.state_.encoder)(actions.state_, process(actions.state_, x));
+ encode_impl(actions.state_, process(actions.state_, x));
     }
 
     template <typename T>
@@ -35,7 +51,9 @@
         return x;
     }
 
+ template void process_action::operator()<std::string>(std::string const&) const;
     template void process_action::operator()<formatted>(formatted const&) const;
+ template void process_action::operator()<block_formatted>(block_formatted const&) const;
     template void process_action::operator()<source_mode>(source_mode const&) const;
     template void process_action::operator()<macro>(macro const&) const;
     template void process_action::operator()<call_template>(call_template const&) const;

Modified: branches/quickbook-1.5-spirit2/state.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/state.cpp (original)
+++ branches/quickbook-1.5-spirit2/state.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -29,7 +29,8 @@
         , doc_title()
 
     // main output stream
- , phrase(out_)
+ , block(out_)
+ , phrase()
         , encoder(encoder)
 
     // state
@@ -74,6 +75,7 @@
         );
 
         phrase.push();
+ block.push();
         templates.push();
     }
 
@@ -90,6 +92,7 @@
         state_stack.pop();
 
         phrase.pop();
+ block.pop();
         templates.pop();
     }
 }

Modified: branches/quickbook-1.5-spirit2/state.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/state.hpp (original)
+++ branches/quickbook-1.5-spirit2/state.hpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -40,6 +40,7 @@
 
     // main output stream
         collector phrase;
+ collector block;
         encoder_ptr encoder;
 
         fs::path outdir;

Modified: branches/quickbook-1.5-spirit2/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/template.cpp 2010-06-12 09:05:58 EDT (Sat, 12 Jun 2010)
@@ -354,7 +354,7 @@
                     ++first; // skip initial newlines
 
                 r = boost::spirit::qi::parse(first, last, g.block) && first == last;
- state.phrase.swap(result);
+ state.block.swap(result);
             }
             
             return r;
@@ -481,7 +481,7 @@
                 quickbook::actions actions(state);
                 actions.process(list);
             }
- result += state.phrase.str();
+ result += state.block.str();
             state.pop();
         }
       


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