Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53452 - branches/quickbook-1.5/detail
From: daniel_james_at_[hidden]
Date: 2009-05-30 09:02:07


Author: danieljames
Date: 2009-05-30 09:02:07 EDT (Sat, 30 May 2009)
New Revision: 53452
URL: http://svn.boost.org/trac/boost/changeset/53452

Log:
Move all the syntax highlighting code into a single class.
Text files modified:
   branches/quickbook-1.5/detail/actions.cpp | 47 +++++++++++++++++-----------------
   branches/quickbook-1.5/detail/actions.hpp | 54 ++++++++++++++++++++-------------------
   branches/quickbook-1.5/detail/actions_class.cpp | 7 ++--
   branches/quickbook-1.5/detail/actions_class.hpp | 1
   4 files changed, 57 insertions(+), 52 deletions(-)

Modified: branches/quickbook-1.5/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5/detail/actions.cpp (original)
+++ branches/quickbook-1.5/detail/actions.cpp 2009-05-30 09:02:07 EDT (Sat, 30 May 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: branches/quickbook-1.5/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5/detail/actions.hpp (original)
+++ branches/quickbook-1.5/detail/actions.hpp 2009-05-30 09:02:07 EDT (Sat, 30 May 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: branches/quickbook-1.5/detail/actions_class.cpp
==============================================================================
--- branches/quickbook-1.5/detail/actions_class.cpp (original)
+++ branches/quickbook-1.5/detail/actions_class.cpp 2009-05-30 09:02:07 EDT (Sat, 30 May 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: branches/quickbook-1.5/detail/actions_class.hpp
==============================================================================
--- branches/quickbook-1.5/detail/actions_class.hpp (original)
+++ branches/quickbook-1.5/detail/actions_class.hpp 2009-05-30 09:02:07 EDT (Sat, 30 May 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;


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