From ef08a8a071d430d2dc972e703c32f90ea860c9c8 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 12 Jun 2010 13:05:58 +0000 Subject: [PATCH] Go back to using separate collectors for blocks and phrases. [SVN r62848] --- actions.cpp | 2 + actions.hpp | 2 + block.hpp | 11 +++- block_actions.cpp | 4 +- block_actions.hpp | 2 +- block_grammar.cpp | 4 +- block_markup_grammar.cpp | 13 ++-- block_table_grammar.cpp | 27 ++++---- boostbook.cpp | 135 ++++++++++++++++++++------------------- code.hpp | 3 +- encoder.hpp | 3 + encoder_impl.hpp | 2 + html.cpp | 127 +++++++++++++++++++----------------- phrase_actions.cpp | 24 ++++--- phrase_actions.hpp | 3 +- phrase_grammar.cpp | 6 +- process.cpp | 20 +++++- state.cpp | 5 +- state.hpp | 1 + template.cpp | 4 +- 20 files changed, 227 insertions(+), 171 deletions(-) diff --git a/actions.cpp b/actions.cpp index bdb41db..4e6c617 100644 --- a/actions.cpp +++ b/actions.cpp @@ -29,6 +29,8 @@ namespace quickbook , process(*this) , phrase_push(state.phrase) , phrase_pop(state.phrase) + , block_push(state.block) + , block_pop(state.block) , error(state.error_count) {} diff --git a/actions.hpp b/actions.hpp index f74ef7a..1e2ab39 100644 --- a/actions.hpp +++ b/actions.hpp @@ -169,6 +169,8 @@ namespace quickbook 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; }; diff --git a/block.hpp b/block.hpp index f8fd6c8..7ea556f 100644 --- a/block.hpp +++ b/block.hpp @@ -19,6 +19,11 @@ namespace quickbook { + struct block_formatted { + formatted_type type; + std::string content; + }; + struct hr { }; @@ -27,7 +32,7 @@ namespace quickbook { std::string content; }; - + struct list_item { file_position position; @@ -67,7 +72,7 @@ namespace quickbook std::string content; }; - typedef std::vector varlistentry; + typedef std::vector varlistentry; struct variablelist { @@ -75,7 +80,7 @@ namespace quickbook std::vector entries; }; - typedef quickbook::formatted table_cell; + typedef quickbook::block_formatted table_cell; typedef std::vector table_row; struct table diff --git a/block_actions.cpp b/block_actions.cpp index 1a9d84b..706a12f 100644 --- a/block_actions.cpp +++ b/block_actions.cpp @@ -36,9 +36,9 @@ namespace quickbook } } - 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; diff --git a/block_actions.hpp b/block_actions.hpp index 7d0bad5..6495d79 100644 --- a/block_actions.hpp +++ b/block_actions.hpp @@ -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&); diff --git a/block_grammar.cpp b/block_grammar.cpp index 94c8843..2d148dd 100644 --- a/block_grammar.cpp +++ b/block_grammar.cpp @@ -75,7 +75,7 @@ namespace quickbook 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 @@ namespace quickbook ) [actions.process] ) >> qi::eps [actions.phrase_pop] - >> (&qi::lit('[') | +eol) + >> (&qi::lit('[') | +eol) ; paragraph_end = diff --git a/block_markup_grammar.cpp b/block_markup_grammar.cpp index 23a79a2..128ea6c 100644 --- a/block_markup_grammar.cpp +++ b/block_markup_grammar.cpp @@ -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 @@ namespace quickbook { // Paragraph Blocks - qi::rule& paragraph_block = store_.create(); + qi::rule& paragraph_block = store_.create(); block_keyword_rules.add ("blurb", paragraph_block(formatted_type("blurb")) [actions.process]) @@ -53,22 +52,22 @@ namespace quickbook ; 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& preformatted = store_.create(); + qi::rule& 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] ; diff --git a/block_table_grammar.cpp b/block_table_grammar.cpp index 52ed644..4a6ce27 100644 --- a/block_table_grammar.cpp +++ b/block_table_grammar.cpp @@ -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 @@ namespace quickbook qi::rule& table = store_.create(); qi::rule& table_row = store_.create(); qi::rule& table_cell = store_.create(); - qi::rule& table_cell_body = store_.create(); + qi::rule& table_cell_body = store_.create(); block_keyword_rules.add("table", table[actions.process]); @@ -73,16 +72,16 @@ namespace quickbook ; 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& variablelist = store_.create(); qi::rule& varlistentry = store_.create(); - qi::rule& varlistterm = store_.create(); - qi::rule& varlistterm_body = store_.create(); - qi::rule& varlistitem = store_.create(); - qi::rule& varlistitem_body = store_.create(); + qi::rule& varlistterm = store_.create(); + qi::rule& varlistterm_body = store_.create(); + qi::rule& varlistitem = store_.create(); + qi::rule& varlistitem_body = store_.create(); block_keyword_rules.add("variablelist", variablelist[actions.process]); @@ -108,26 +107,26 @@ namespace quickbook 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 diff --git a/boostbook.cpp b/boostbook.cpp index cf22fe5..c2b5919 100644 --- a/boostbook.cpp +++ b/boostbook.cpp @@ -54,7 +54,6 @@ namespace quickbook boostbook_markup markups[] = { { "", "", "" }, - { "comment", "" }, { "paragraph", "\n", "\n" }, { "h1", "", "" }, { "h2", "", "" }, @@ -173,6 +172,12 @@ namespace quickbook 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 @@ namespace quickbook 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
\n"; + state.block << "\n
\n"; if(x.linkend.empty()) { - state.phrase + state.block << "" << x.content << "\n" ; } else { - state.phrase + state.block << "" << "<link linkend=\"" << encode(x.linkend) @@ -243,123 +248,123 @@ namespace quickbook 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 << "\n"; + state.block << ""; + state.block << encode(x.title); + state.block << "\n"; boostbook_markup m = get_markup("varlistentry"); for(std::vector::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 << "\n"; + state.block << "\n"; } void boostbook_encoder::operator()(quickbook::state& state, table2 const& x) { if (x.title) { - state.phrase << "\n"; - state.phrase << ""; - state.phrase << encode(*x.title); - state.phrase << ""; + state.block << " id=\"" << encode(*x.id) << "\""; + state.block << ">\n"; + state.block << ""; + state.block << encode(*x.title); + state.block << ""; } else { - 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 << "\n"; + state.block << "\n"; boostbook_markup m = get_markup("row"); if (x.head) { - state.phrase << ""; - state.phrase << m.pre; + state.block << ""; + state.block << m.pre; std::for_each(x.head->begin(), x.head->end(), encode_action(state, *this)); - state.phrase << m.post; - state.phrase << "\n"; + state.block << m.post; + state.block << "\n"; } - state.phrase << "\n"; + state.block << "\n"; for(std::vector::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 << "\n" << "\n"; + state.block << "\n" << "\n"; if (x.title) { - state.phrase << "
\n"; + state.block << "\n"; } else { - state.phrase << "\n"; + state.block << "\n"; } } void boostbook_encoder::operator()(quickbook::state& state, xinclude2 const& x) { - state.phrase << "\n\n"; + state.block << "\n\n"; } void boostbook_encoder::operator()(quickbook::state& state, list2 const& x) { - state.phrase << std::string(x.mark == '#' ? "\n" : "\n"); + state.block << std::string(x.mark == '#' ? "\n" : "\n"); for(std::vector::const_iterator it = x.items.begin(), end = x.items.end(); it != end; ++it) { - state.phrase << "\n" << it->content; + state.block << "\n" << it->content; if(!it->sublist.items.empty()) (*this)(state, it->sublist); - state.phrase << std::string("\n"); + state.block << std::string("\n"); } - state.phrase << std::string(x.mark == '#' ? "\n" : "\n"); + state.block << std::string(x.mark == '#' ? "\n" : "\n"); } void boostbook_encoder::operator()(quickbook::state& state, callout_link const& x) @@ -373,12 +378,12 @@ namespace quickbook void boostbook_encoder::operator()(quickbook::state& state, callout_list const& x) { - state.phrase + state.block << ""; BOOST_FOREACH(callout_item const& c, x) { - state.phrase + state.block << "" @@ -386,7 +391,7 @@ namespace quickbook << ""; } - state.phrase + state.block << ""; } @@ -409,7 +414,7 @@ namespace quickbook // if we're ignoring the document info, we're done. if (info.ignore) return; - state.phrase + state.block << "\n" << ""; // end document tag. + state.block << ">"; // end document tag. // Title tag @@ -449,35 +454,35 @@ namespace quickbook } // 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 << "\n"; + state.block << "\n"; BOOST_FOREACH(doc_info::author const& author, info.doc_authors) { - state.phrase + state.block << "\n" << "" << author.firstname << "\n" << "" << author.surname << "\n" << "\n"; } - state.phrase << "\n"; + state.block << "\n"; } BOOST_FOREACH(doc_info::copyright_entry const& copyright, info.doc_copyrights) { - state.phrase << "\n"; + state.block << "\n"; BOOST_FOREACH(unsigned int year, copyright.years) { - state.phrase << "" << year << "\n"; + state.block << "" << year << "\n"; } - state.phrase + state.block << "" << copyright.holder << "\n" << "\n" ; @@ -485,7 +490,7 @@ namespace quickbook if (!boost::apply_visitor(empty_visitor(), info.doc_license)) { - state.phrase + state.block << "\n" << "\n" << boost::apply_visitor(encode_raw_visitor(*this), info.doc_license) @@ -498,7 +503,7 @@ namespace quickbook 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) << "\n" @@ -508,7 +513,7 @@ namespace quickbook BOOST_FOREACH(raw_string const& category, info.doc_categories) { - state.phrase + state.block << "<" << info.doc_type << "category name=\"category:" << encode(category) << "\">\n" @@ -516,11 +521,11 @@ namespace quickbook ; } - state.phrase + state.block << "\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 @@ namespace quickbook // We've finished generating our output. Here's what we'll do // *after* everything else. - state.phrase << ""; + state.block << ""; } } diff --git a/code.hpp b/code.hpp index 203ec6b..e4c24b5 100644 --- a/code.hpp +++ b/code.hpp @@ -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; }; diff --git a/encoder.hpp b/encoder.hpp index 91958f9..7ea8203 100644 --- a/encoder.hpp +++ b/encoder.hpp @@ -46,6 +46,7 @@ namespace quickbook 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 @@ namespace quickbook struct encode_action { + typedef void result_type; + encode_action(quickbook::state& state, quickbook::encoder& encoder) : state(state), encoder(encoder) {} diff --git a/encoder_impl.hpp b/encoder_impl.hpp index 37a4853..057e06c 100644 --- a/encoder_impl.hpp +++ b/encoder_impl.hpp @@ -30,6 +30,7 @@ namespace quickbook 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 @@ namespace quickbook 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&); diff --git a/html.cpp b/html.cpp index 238011d..1a55074 100644 --- a/html.cpp +++ b/html.cpp @@ -54,11 +54,11 @@ namespace quickbook char const* quickbook; char const* pre; char const* post; + bool block; }; html_markup markups[] = { { "", "", "" }, - { "comment", "" }, { "paragraph", "

\n", "

\n" }, { "blurb", "
\n", "
\n" }, { "blockquote", "
", "
" }, @@ -191,6 +191,13 @@ namespace quickbook } } + 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 @@ namespace quickbook 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 @@ namespace quickbook int level = state.section_level + 1; if (level > 6) level = 6; - state.phrase << "\n
\n"; + state.block << "\n
\n"; if(x.linkend.empty()) { - state.phrase + state.block << "" << x.content << "\n" ; } else { - state.phrase + state.block << "" @@ -261,91 +268,91 @@ namespace quickbook { pop_footnotes(state); - state.phrase << "
"; + state.block << "
"; } void html_encoder::operator()(quickbook::state& state, heading2 const& x) { - state.phrase + state.block << "" ; if(!x.linkend.empty()) { - state.phrase + state.block << "" ; } - state.phrase << x.content; + state.block << x.content; - state.phrase << ""; + state.block << ""; } void html_encoder::operator()(quickbook::state& state, variablelist const& x) { // TODO: What should I do for the title? - state.phrase << "

"; - state.phrase << encode(x.title); - state.phrase << "

\n"; + state.block << "

"; + state.block << encode(x.title); + state.block << "

\n"; - state.phrase << "
\n"; + state.block << "
\n"; html_markup m = get_markup("varlistentry"); for(std::vector::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 << "
\n"; + state.block << "
\n"; } void html_encoder::operator()(quickbook::state& state, table2 const& x) { if (x.title) { - state.phrase << "\n"; - state.phrase << ""; - state.phrase << encode(*x.title); - state.phrase << ""; + state.block << " id=\"" << encode(*x.id) << "\""; + state.block << ">\n"; + state.block << ""; + state.block << encode(*x.title); + state.block << ""; } else { - state.phrase << "\n"; + state.block << " id=\"" << encode(*x.id) << "\""; + state.block << ">\n"; } html_markup m = get_markup("row"); if (x.head) { - state.phrase << ""; - state.phrase << m.pre; + state.block << ""; + state.block << m.pre; std::for_each(x.head->begin(), x.head->end(), encode_action(state, *this)); - state.phrase << m.post; - state.phrase << "\n"; + state.block << m.post; + state.block << "\n"; } - state.phrase << "\n"; + state.block << "\n"; for(std::vector::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 << "\n"; + state.block << "\n"; - state.phrase << "\n"; + state.block << "\n"; } void html_encoder::operator()(quickbook::state& state, xinclude2 const& x) @@ -356,17 +363,17 @@ namespace quickbook void html_encoder::operator()(quickbook::state& state, list2 const& x) { - state.phrase << std::string(x.mark == '#' ? "
    \n" : "
      \n"); + state.block << std::string(x.mark == '#' ? "
        \n" : "
          \n"); for(std::vector::const_iterator it = x.items.begin(), end = x.items.end(); it != end; ++it) { - state.phrase << "
        • \n" << it->content; + state.block << "
        • \n" << it->content; if(!it->sublist.items.empty()) (*this)(state, it->sublist); - state.phrase << std::string("\n
        • "); + state.block << std::string("\n"); } - state.phrase << std::string(x.mark == '#' ? "\n
      " : "\n
    "); + state.block << std::string(x.mark == '#' ? "\n
" : "\n"); } void html_encoder::operator()(quickbook::state& state, callout_link const& x) @@ -387,13 +394,13 @@ namespace quickbook void html_encoder::operator()(quickbook::state& state, callout_list const& x) { - state.phrase + state.block << "
"; unsigned int count = 0; BOOST_FOREACH(callout_item const& c, x) { - state.phrase + state.block << "
" << "" << "callout " << ++count @@ -405,7 +412,7 @@ namespace quickbook ; } - state.phrase + state.block << ""; } @@ -428,7 +435,7 @@ namespace quickbook // if we're ignoring the document info, we're done. if (info.ignore) return; - state.phrase + state.block << "" << "" << "" << encode(info.doc_title) << "" @@ -443,18 +450,18 @@ namespace quickbook !boost::apply_visitor(empty_visitor(), info.doc_license)) { - state.phrase << "
\n"; + state.block << "
\n"; if(!info.doc_authors.empty()) { - state.phrase + state.block << "
" << (info.doc_authors.size() == 1 ? "Author:" : "Authors:") << "
\n" ; BOOST_FOREACH(doc_info::author const& author, info.doc_authors) { - state.phrase + state.block << "
" << author.firstname << " " @@ -465,21 +472,21 @@ namespace quickbook if(!info.doc_copyrights.empty()) { - state.phrase + state.block << "
Copyright:
\n" ; BOOST_FOREACH(doc_info::copyright_entry const& copyright, info.doc_copyrights) { - state.phrase << "
© "; + state.block << "
© "; 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 @@ namespace quickbook 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 << "
\n" @@ -512,7 +519,7 @@ namespace quickbook if (!boost::apply_visitor(empty_visitor(), info.doc_license)) { - state.phrase + state.block << "
License:
\n" << "
" << boost::apply_visitor(encode_raw_visitor(*this), info.doc_license) @@ -520,10 +527,10 @@ namespace quickbook ; } - state.phrase << "
\n"; + state.block << "
\n"; } - state.phrase + state.block << "\n" ; @@ -539,7 +546,7 @@ namespace quickbook // We've finished generating our output. Here's what we'll do // *after* everything else. - state.phrase << ""; + state.block << ""; } void html_encoder::push_footnotes(quickbook::state& state) @@ -554,11 +561,11 @@ namespace quickbook footnote_stack.pop(); if(!notes.empty()) { - state.phrase + state.block << "
\n"; BOOST_FOREACH(footnote const& x, notes) { - state.phrase + state.block << "
" << "" << "Footnote" @@ -570,7 +577,7 @@ namespace quickbook ; } - state.phrase + state.block << "
\n"; } } diff --git a/phrase_actions.cpp b/phrase_actions.cpp index 26ffdbf..750d914 100644 --- a/phrase_actions.cpp +++ b/phrase_actions.cpp @@ -81,15 +81,14 @@ namespace quickbook return x; } - formatted process(quickbook::state& state, code const& x) { - formatted r; - r.type = ""; - + boost::variant 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 @@ namespace quickbook 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; + } } } diff --git a/phrase_actions.hpp b/phrase_actions.hpp index e51b1aa..875a08b 100644 --- a/phrase_actions.hpp +++ b/phrase_actions.hpp @@ -10,6 +10,7 @@ #if !defined(BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP) #define BOOST_SPIRIT_QUICKBOOK_PHRASE_ACTIONS_HPP +#include #include "phrase.hpp" #include "code.hpp" #include "gen_types.hpp" @@ -22,7 +23,7 @@ namespace quickbook 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 process(quickbook::state&, code const&); image2 process(quickbook::state&, image const&); std::string process(quickbook::state&, call_template const&); } diff --git a/phrase_grammar.cpp b/phrase_grammar.cpp index f734dca..c401808 100644 --- a/phrase_grammar.cpp +++ b/phrase_grammar.cpp @@ -146,14 +146,14 @@ namespace quickbook ( "```" >> 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 @@ namespace quickbook 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)] >> '`' ; diff --git a/process.cpp b/process.cpp index f546ad9..e60a281 100644 --- a/process.cpp +++ b/process.cpp @@ -20,13 +20,29 @@ #include "template.hpp" #include "doc_info_actions.hpp" #include "encoder.hpp" +#include namespace quickbook { + namespace { + template + inline void encode_impl(state& state_, T const& x) + { + (*state_.encoder)(state_, x); + } + + template + inline void encode_impl(state& state_, boost::variant const& x) + { + encode_action visitor(state_, *state_.encoder); + boost::apply_visitor(visitor, x); + } + } + template 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 @@ -35,7 +51,9 @@ namespace quickbook return x; } + template void process_action::operator()(std::string const&) const; template void process_action::operator()(formatted const&) const; + template void process_action::operator()(block_formatted const&) const; template void process_action::operator()(source_mode const&) const; template void process_action::operator()(macro const&) const; template void process_action::operator()(call_template const&) const; diff --git a/state.cpp b/state.cpp index bc0a848..f277f99 100644 --- a/state.cpp +++ b/state.cpp @@ -29,7 +29,8 @@ namespace quickbook , doc_title() // main output stream - , phrase(out_) + , block(out_) + , phrase() , encoder(encoder) // state @@ -74,6 +75,7 @@ namespace quickbook ); phrase.push(); + block.push(); templates.push(); } @@ -90,6 +92,7 @@ namespace quickbook state_stack.pop(); phrase.pop(); + block.pop(); templates.pop(); } } diff --git a/state.hpp b/state.hpp index 088a5a5..d819b7c 100644 --- a/state.hpp +++ b/state.hpp @@ -40,6 +40,7 @@ namespace quickbook // main output stream collector phrase; + collector block; encoder_ptr encoder; fs::path outdir; diff --git a/template.cpp b/template.cpp index 4fee10a..68270ba 100644 --- a/template.cpp +++ b/template.cpp @@ -354,7 +354,7 @@ namespace quickbook ++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 @@ namespace quickbook quickbook::actions actions(state); actions.process(list); } - result += state.phrase.str(); + result += state.block.str(); state.pop(); }