Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85366 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-08-16 13:30:49


Author: danieljames
Date: 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013)
New Revision: 85366
URL: http://svn.boost.org/trac/boost/changeset/85366

Log:
Hard-code which collector is written to.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 65 +++++++++++++++++++--------------------
   trunk/tools/quickbook/src/actions.hpp | 35 ++++++---------------
   trunk/tools/quickbook/src/block_element_grammar.cpp | 2
   trunk/tools/quickbook/src/doc_info_grammar.cpp | 4 +-
   trunk/tools/quickbook/src/main_grammar.cpp | 12 +++---
   trunk/tools/quickbook/src/phrase_element_grammar.cpp | 2
   trunk/tools/quickbook/src/syntax_highlight.cpp | 40 +++++++++++-------------
   7 files changed, 70 insertions(+), 90 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/actions.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -198,7 +198,7 @@
 
     void break_action::operator()(parse_iterator first, parse_iterator) const
     {
- write_anchors(state, phrase);
+ write_anchors(state, state.phrase);
 
         if(*first == '\\')
         {
@@ -216,7 +216,7 @@
             state.warned_about_breaks = true;
         }
             
- phrase << detail::get_markup(phrase_tags::break_mark).pre;
+ state.phrase << detail::get_markup(phrase_tags::break_mark).pre;
     }
 
     void error_message_action::operator()(parse_iterator first, parse_iterator last) const
@@ -452,7 +452,7 @@
 
     void simple_phrase_action::operator()(char mark) const
     {
- write_anchors(state, out);
+ write_anchors(state, state.phrase);
 
         int tag =
             mark == '*' ? phrase_tags::bold :
@@ -468,9 +468,9 @@
         value content = values.consume();
         values.finish();
 
- out << markup.pre;
- out << content.get_encoded();
- out << markup.post;
+ state.phrase << markup.pre;
+ state.phrase << content.get_encoded();
+ state.phrase << markup.post;
     }
 
     bool cond_phrase_push::start()
@@ -670,35 +670,35 @@
 
     void do_macro_action::operator()(std::string const& str) const
     {
- write_anchors(state, phrase);
+ write_anchors(state, state.phrase);
 
         if (str == quickbook_get_date)
         {
             char strdate[64];
             strftime(strdate, sizeof(strdate), "%Y-%b-%d", current_time);
- phrase << strdate;
+ state.phrase << strdate;
         }
         else if (str == quickbook_get_time)
         {
             char strdate[64];
             strftime(strdate, sizeof(strdate), "%I:%M:%S %p", current_time);
- phrase << strdate;
+ state.phrase << strdate;
         }
         else
         {
- phrase << str;
+ state.phrase << str;
         }
     }
 
     void raw_char_action::operator()(char ch) const
     {
- out << ch;
+ state.phrase << ch;
     }
 
     void raw_char_action::operator()(parse_iterator first, parse_iterator last) const
     {
         while (first != last)
- out << *first++;
+ state.phrase << *first++;
     }
 
     void source_mode_action(quickbook::state& state, value source_mode)
@@ -758,52 +758,50 @@
             boost::swap(state.current_file, saved_file);
 
             // print the code with syntax coloring
- std::string str = syntax_highlight(first_, last_, state,
- source_mode, block);
+ //
+ // We must not place a \n after the <programlisting> tag
+ // otherwise PDF output starts code blocks with a blank line:
+ state.phrase << "<programlisting>";
+ syntax_highlight(first_, last_, state, source_mode, block);
+ state.phrase << "</programlisting>\n";
 
             boost::swap(state.current_file, saved_file);
 
- collector& output = inline_code ? state.phrase : state.out;
+ if (qbk_version_n >= 107u) state.phrase << state.end_callouts();
 
- // We must not place a \n after the <programlisting> tag
- // otherwise PDF output starts code blocks with a blank line:
- //
- output << "<programlisting>";
- output << str;
- output << "</programlisting>\n";
-
- if (qbk_version_n >= 107u) output << state.end_callouts();
+ if (!inline_code) {
+ state.out << state.phrase.str();
+ state.phrase.clear();
+ }
         }
         else {
             parse_iterator first_(code_value.begin());
             parse_iterator last_(code_value.end());
- std::string str = syntax_highlight(first_, last_, state,
- source_mode, block);
 
             state.phrase << "<code>";
- state.phrase << str;
+ syntax_highlight(first_, last_, state, source_mode, block);
             state.phrase << "</code>";
         }
     }
 
     void plain_char_action::operator()(char ch) const
     {
- write_anchors(state, phrase);
+ write_anchors(state, state.phrase);
 
- detail::print_char(ch, phrase.get());
+ detail::print_char(ch, state.phrase.get());
     }
 
     void plain_char_action::operator()(parse_iterator first, parse_iterator last) const
     {
- write_anchors(state, phrase);
+ write_anchors(state, state.phrase);
 
         while (first != last)
- detail::print_char(*first++, phrase.get());
+ detail::print_char(*first++, state.phrase.get());
     }
 
     void escape_unicode_action::operator()(parse_iterator first, parse_iterator last) const
     {
- write_anchors(state, phrase);
+ write_anchors(state, state.phrase);
 
         while(first != last && *first == '0') ++first;
 
@@ -815,10 +813,11 @@
         
         if(hex_digits.size() == 2 && *first > '0' && *first <= '7') {
             using namespace std;
- detail::print_char(strtol(hex_digits.c_str(), 0, 16), phrase.get());
+ detail::print_char(strtol(hex_digits.c_str(), 0, 16),
+ state.phrase.get());
         }
         else {
- phrase << "&#x" << hex_digits << ";";
+ state.phrase << "&#x" << hex_digits << ";";
         }
     }
 

Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/actions.hpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -46,7 +46,7 @@
     int load_snippets(fs::path const& file, std::vector<template_symbol>& storage,
         std::string const& extension, value::tag_type load_type);
 
- std::string syntax_highlight(
+ void syntax_highlight(
         parse_iterator first, parse_iterator last,
         quickbook::state& state,
         std::string const& source_mode,
@@ -149,15 +149,11 @@
     {
         // Handles simple text formats
 
- simple_phrase_action(
- collector& out
- , quickbook::state& state)
- : out(out)
- , state(state) {}
+ simple_phrase_action(quickbook::state& state)
+ : state(state) {}
 
         void operator()(char) const;
 
- collector& out;
         quickbook::state& state;
     };
 
@@ -178,12 +174,9 @@
     {
         // Handles macro substitutions
 
- do_macro_action(collector& phrase, quickbook::state& state)
- : phrase(phrase)
- , state(state) {}
+ do_macro_action(quickbook::state& state) : state(state) {}
 
         void operator()(std::string const& str) const;
- collector& phrase;
         quickbook::state& state;
     };
 
@@ -191,13 +184,12 @@
     {
         // Prints a space
 
- raw_char_action(collector& out)
- : out(out) {}
+ raw_char_action(quickbook::state& state) : state(state) {}
 
         void operator()(char ch) const;
         void operator()(parse_iterator first, parse_iterator last) const;
 
- collector& out;
+ quickbook::state& state;
     };
 
     struct plain_char_action
@@ -205,36 +197,29 @@
         // Prints a single plain char.
         // Converts '<' to "&lt;"... etc See utils.hpp
 
- plain_char_action(collector& phrase, quickbook::state& state)
- : phrase(phrase)
- , state(state) {}
+ plain_char_action(quickbook::state& state) : state(state) {}
 
         void operator()(char ch) const;
         void operator()(parse_iterator first, parse_iterator last) const;
 
- collector& phrase;
         quickbook::state& state;
     };
     
     struct escape_unicode_action
     {
- escape_unicode_action(collector& phrase, quickbook::state& state)
- : phrase(phrase)
- , state(state) {}
+ escape_unicode_action(quickbook::state& state) : state(state) {}
+
         void operator()(parse_iterator first, parse_iterator last) const;
 
- collector& phrase;
         quickbook::state& state;
     };
 
     struct break_action
     {
- break_action(collector& phrase, quickbook::state& state)
- : phrase(phrase), state(state) {}
+ break_action(quickbook::state& state) : state(state) {}
 
         void operator()(parse_iterator f, parse_iterator) const;
 
- collector& phrase;
         quickbook::state& state;
     };
 

Modified: trunk/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/block_element_grammar.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/block_element_grammar.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -47,7 +47,7 @@
         // Actions
         error_action error(state);
         element_id_warning_action element_id_warning(state);
- raw_char_action raw_char(state.phrase);
+ raw_char_action raw_char(state);
         explicit_list_action explicit_list(state);
         scoped_parser<to_value_scoped_action> to_value(state);
 

Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -118,8 +118,8 @@
 
         // Actions
         error_action error(state);
- plain_char_action plain_char(state.phrase, state);
- do_macro_action do_macro(state.phrase, state);
+ plain_char_action plain_char(state);
+ do_macro_action do_macro(state);
         scoped_parser<to_value_scoped_action> to_value(state);
         
         doc_info_details =

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -304,14 +304,14 @@
         quickbook::paragraph_action paragraph_action(state);
 
         phrase_end_action end_phrase(state);
- raw_char_action raw_char(state.phrase);
- plain_char_action plain_char(state.phrase, state);
- escape_unicode_action escape_unicode(state.phrase, state);
+ raw_char_action raw_char(state);
+ plain_char_action plain_char(state);
+ escape_unicode_action escape_unicode(state);
 
- simple_phrase_action simple_markup(state.phrase, state);
+ simple_phrase_action simple_markup(state);
 
- break_action break_(state.phrase, state);
- do_macro_action do_macro(state.phrase, state);
+ break_action break_(state);
+ do_macro_action do_macro(state);
 
         error_action error(state);
         element_id_warning_action element_id_warning(state);

Modified: trunk/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_element_grammar.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/phrase_element_grammar.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -38,7 +38,7 @@
             new phrase_element_grammar_local);
 
         error_action error(state);
- raw_char_action raw_char(state.phrase);
+ raw_char_action raw_char(state);
         scoped_parser<cond_phrase_push> scoped_cond_phrase(state);
         scoped_parser<to_value_scoped_action> to_value(state);
 

Modified: trunk/tools/quickbook/src/syntax_highlight.cpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.cpp Fri Aug 16 12:58:05 2013 (r85365)
+++ trunk/tools/quickbook/src/syntax_highlight.cpp 2013-08-16 13:30:49 EDT (Fri, 16 Aug 2013) (r85366)
@@ -87,7 +87,6 @@
 
     struct syntax_highlight_actions
     {
- quickbook::collector out;
         quickbook::state& state;
         do_macro_action do_macro_impl;
 
@@ -96,8 +95,8 @@
         boost::string_ref marked_text;
 
         syntax_highlight_actions(quickbook::state& state, bool is_block) :
- out(), state(state),
- do_macro_impl(out, state),
+ state(state),
+ do_macro_impl(state),
             support_callouts(is_block && (qbk_version_n >= 107u ||
                 state.current_file->is_code_snippets)),
             marked_text()
@@ -119,26 +118,26 @@
     void syntax_highlight_actions::span(parse_iterator first,
             parse_iterator last, char const* name)
     {
- out << "<phrase role=\"" << name << "\">";
+ state.phrase << "<phrase role=\"" << name << "\">";
         while (first != last)
- detail::print_char(*first++, out.get());
- out << "</phrase>";
+ detail::print_char(*first++, state.phrase.get());
+ state.phrase << "</phrase>";
     }
 
     void syntax_highlight_actions::span_start(parse_iterator first,
             parse_iterator last, char const* name)
     {
- out << "<phrase role=\"" << name << "\">";
+ state.phrase << "<phrase role=\"" << name << "\">";
         while (first != last)
- detail::print_char(*first++, out.get());
+ detail::print_char(*first++, state.phrase.get());
     }
 
     void syntax_highlight_actions::span_end(parse_iterator first,
             parse_iterator last)
     {
         while (first != last)
- detail::print_char(*first++, out.get());
- out << "</phrase>";
+ detail::print_char(*first++, state.phrase.get());
+ state.phrase << "</phrase>";
     }
 
     void syntax_highlight_actions::unexpected_char(parse_iterator first,
@@ -152,17 +151,17 @@
             << "\n";
 
         // print out an unexpected character
- out << "<phrase role=\"error\">";
+ state.phrase << "<phrase role=\"error\">";
         while (first != last)
- detail::print_char(*first++, out.get());
- out << "</phrase>";
+ detail::print_char(*first++, state.phrase.get());
+ state.phrase << "</phrase>";
     }
 
     void syntax_highlight_actions::plain_char(parse_iterator first,
             parse_iterator last)
     {
         while (first != last)
- detail::print_char(*first++, out.get());
+ detail::print_char(*first++, state.phrase.get());
     }
 
     void syntax_highlight_actions::pre_escape_back(parse_iterator,
@@ -174,8 +173,10 @@
     void syntax_highlight_actions::post_escape_back(parse_iterator,
             parse_iterator)
     {
- out << state.phrase.str();
+ std::string tmp;
+ state.phrase.swap(tmp);
         state.pop_output(); // restore the stream
+ state.phrase << tmp;
     }
 
     void syntax_highlight_actions::do_macro(std::string const& v)
@@ -191,7 +192,7 @@
 
     void syntax_highlight_actions::callout(parse_iterator, parse_iterator)
     {
- out << state.add_callout(qbk_value(state.current_file,
+ state.phrase << state.add_callout(qbk_value(state.current_file,
             marked_text.begin(), marked_text.end()));
         marked_text.clear();
     }
@@ -619,7 +620,7 @@
         syntax_highlight_actions& actions;
     };
 
- std::string syntax_highlight(
+ void syntax_highlight(
         parse_iterator first,
         parse_iterator last,
         quickbook::state& state,
@@ -648,10 +649,5 @@
         {
             BOOST_ASSERT(0);
         }
-
- std::string str;
- syn_actions.out.swap(str);
-
- return str;
     }
 }


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