$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54813 - trunk/tools/quickbook/detail
From: daniel_james_at_[hidden]
Date: 2009-07-08 17:40:25
Author: danieljames
Date: 2009-07-08 17:40:24 EDT (Wed, 08 Jul 2009)
New Revision: 54813
URL: http://svn.boost.org/trac/boost/changeset/54813
Log:
Move all the syntax highlighting code into a single class.
Text files modified: 
   trunk/tools/quickbook/detail/actions.cpp       |    47 +++++++++++++++++-----------------      
   trunk/tools/quickbook/detail/actions.hpp       |    54 ++++++++++++++++++++------------------- 
   trunk/tools/quickbook/detail/actions_class.cpp |     7 ++--                                    
   trunk/tools/quickbook/detail/actions_class.hpp |     1                                         
   4 files changed, 57 insertions(+), 52 deletions(-)
Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp	(original)
+++ trunk/tools/quickbook/detail/actions.cpp	2009-07-08 17:40:24 EDT (Wed, 08 Jul 2009)
@@ -308,12 +308,27 @@
         out << escape_actions.phrase.str();
         escape_actions.phrase.pop(); // restore the stream
     }
+    
+    std::string syntax_highlight::operator()(iterator first, iterator last) const
+    {
+        // print the code with syntax coloring
+        if (source_mode == "c++")
+        {
+            parse(first, last, cpp_p);
+        }
+        else if (source_mode == "python")
+        {
+            parse(first, last, python_p);
+        }
+
+        std::string str;
+        temp.swap(str);
+        
+        return str;
+    }
 
     void code_action::operator()(iterator first, iterator last) const
     {
-        std::string save;
-        phrase.swap(save);
-
         // preprocess the code section to remove the initial indentation
         std::string program(first, last);
         detail::unindent(program);
@@ -324,18 +339,12 @@
         iterator last_(program.end(), program.end());
         first_.set_position(first.get_position());
 
+        std::string save;
+        phrase.swap(save);
+
         // print the code with syntax coloring
-        if (source_mode == "c++")
-        {
-            parse(first_, last_, cpp_p);
-        }
-        else if (source_mode == "python")
-        {
-            parse(first_, last_, python_p);
-        }
+        std::string str = syntax_p(first_, last_);
 
-        std::string str;
-        temp.swap(str);
         phrase.swap(save);
 
         //
@@ -353,16 +362,8 @@
         out.swap(save);
 
         // print the code with syntax coloring
-        if (source_mode == "c++")
-        {
-            parse(first, last, cpp_p);
-        }
-        else if (source_mode == "python")
-        {
-            parse(first, last, python_p);
-        }
-        std::string str;
-        temp.swap(str);
+        std::string str = syntax_p(first, last);
+
         out.swap(save);
 
         out << "<code>";
Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp	(original)
+++ trunk/tools/quickbook/detail/actions.hpp	2009-07-08 17:40:24 EDT (Wed, 08 Jul 2009)
@@ -368,6 +368,28 @@
       , unexpected_char
       , collector>
     python_p_type;
+    
+    struct syntax_highlight
+    {
+        syntax_highlight(
+            collector& temp
+          , std::string const& source_mode
+          , string_symbols const& macro
+          , actions& escape_actions)
+        : temp(temp)
+        , source_mode(source_mode)
+        , cpp_p(temp, macro, do_macro_action(temp), escape_actions)
+        , python_p(temp, macro, do_macro_action(temp), escape_actions)
+        {
+        }
+
+        std::string operator()(iterator first, iterator last) const;
+
+        collector& temp;
+        std::string const& source_mode;
+        cpp_p_type cpp_p;
+        python_p_type python_p;
+    };
 
     struct code_action
     {
@@ -376,16 +398,10 @@
         code_action(
             collector& out
           , collector& phrase
-          , collector& temp
-          , std::string const& source_mode
-          , string_symbols const& macro
-          , actions& escape_actions)
+          , syntax_highlight& syntax_p)
         : out(out)
         , phrase(phrase)
-        , temp(temp)
-        , source_mode(source_mode)
-        , cpp_p(temp, macro, do_macro_action(temp), escape_actions)
-        , python_p(temp, macro, do_macro_action(temp), escape_actions)
+        , syntax_p(syntax_p)
         {
         }
 
@@ -393,11 +409,7 @@
 
         collector& out;
         collector& phrase;
-        collector& temp;
-        std::string const& source_mode;
-
-        cpp_p_type cpp_p;
-        python_p_type python_p;
+        syntax_highlight& syntax_p;
     };
 
     struct inline_code_action
@@ -406,25 +418,15 @@
 
         inline_code_action(
             collector& out
-          , collector& temp
-          , std::string const& source_mode
-          , string_symbols const& macro
-          , actions& escape_actions)
+          , syntax_highlight& syntax_p)
         : out(out)
-        , source_mode(source_mode)
-        , temp(temp)
-        , cpp_p(temp, macro, do_macro_action(temp), escape_actions)
-        , python_p(temp, macro, do_macro_action(temp), escape_actions)
+        , syntax_p(syntax_p)
         {}
 
         void operator()(iterator first, iterator last) const;
 
         collector& out;
-        std::string const& source_mode;
-        collector& temp;
-
-        cpp_p_type cpp_p;
-        python_p_type python_p;
+        syntax_highlight& syntax_p;
     };
 
     struct raw_char_action
Modified: trunk/tools/quickbook/detail/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.cpp	(original)
+++ trunk/tools/quickbook/detail/actions_class.cpp	2009-07-08 17:40:24 EDT (Wed, 08 Jul 2009)
@@ -69,9 +69,10 @@
         , extract_doc_license(doc_license, phrase)
         , extract_doc_purpose(doc_purpose, phrase)
 
-        , code(out, phrase, temp, source_mode, macro, *this)
-        , code_block(phrase, phrase, temp, source_mode, macro, *this)
-        , inline_code(phrase, temp, source_mode, macro, *this)
+        , syntax_p(temp, source_mode, macro, *this)
+        , code(out, phrase, syntax_p)
+        , code_block(phrase, phrase, syntax_p)
+        , inline_code(phrase, syntax_p)
         , paragraph(out, phrase, paragraph_pre, paragraph_post)
         , inside_paragraph(temp_para, phrase, paragraph_pre, paragraph_post)
         , h(out, phrase, doc_id, section_id, qualified_section_id, section_level)
Modified: trunk/tools/quickbook/detail/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.hpp	(original)
+++ trunk/tools/quickbook/detail/actions_class.hpp	2009-07-08 17:40:24 EDT (Wed, 08 Jul 2009)
@@ -103,6 +103,7 @@
         phrase_to_string_action extract_doc_license;
         phrase_to_string_action extract_doc_purpose;
 
+        syntax_highlight        syntax_p;
         code_action             code;
         code_action             code_block;
         inline_code_action      inline_code;