Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57770 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2009-11-18 18:09:46


Author: danieljames
Date: 2009-11-18 18:09:45 EST (Wed, 18 Nov 2009)
New Revision: 57770
URL: http://svn.boost.org/trac/boost/changeset/57770

Log:
Instantiate the syntax highlighters in a separate compile unit.
Added:
   branches/quickbook-1.5-spirit2/detail/syntax_highlight.cpp (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 1
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 26 --------------------
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 50 ++++++---------------------------------
   3 files changed, 9 insertions(+), 68 deletions(-)

Modified: branches/quickbook-1.5-spirit2/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/Jamfile.v2 2009-11-18 18:09:45 EST (Wed, 18 Nov 2009)
@@ -31,6 +31,7 @@
     detail/block.cpp
     detail/doc_info.cpp
     detail/code_snippet.cpp
+ detail/syntax_highlight.cpp
     /boost//program_options
     /boost//filesystem
     : #<define>QUICKBOOK_NO_DATES

Modified: branches/quickbook-1.5-spirit2/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.cpp 2009-11-18 18:09:45 EST (Wed, 18 Nov 2009)
@@ -323,32 +323,6 @@
         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);
- }
- else if (source_mode == "teletype")
- {
- parse(first, last, teletype_p);
- }
- else
- {
- BOOST_ASSERT(0);
- }
-
- std::string str;
- temp.swap(str);
-
- return str;
- }
 
     void code_action::operator()(iterator first, iterator last) const
     {

Modified: branches/quickbook-1.5-spirit2/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.hpp 2009-11-18 18:09:45 EST (Wed, 18 Nov 2009)
@@ -20,7 +20,6 @@
 #include <boost/filesystem/operations.hpp>
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
-#include "../syntax_highlight.hpp"
 #include "./collector.hpp"
 #include "./template_stack.hpp"
 #include "./utils.hpp"
@@ -33,6 +32,8 @@
 
 namespace quickbook
 {
+ using namespace boost::spirit::classic;
+
     namespace fs = boost::filesystem;
     typedef position_iterator<std::string::const_iterator> iterator;
     typedef symbols<std::string> string_symbols;
@@ -425,40 +426,6 @@
         collector& phrase;
         std::string str;
     };
-
- typedef cpp_highlight<
- span
- , space
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , actions
- , unexpected_char
- , collector>
- cpp_p_type;
-
- typedef python_highlight<
- span
- , space
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , actions
- , unexpected_char
- , collector>
- python_p_type;
-
- typedef teletype_highlight<
- plain_char_action
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , actions
- , collector>
- teletype_p_type;
     
     struct syntax_highlight
     {
@@ -469,21 +436,20 @@
           , 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)
- , teletype_p(temp, macro, do_macro_action(temp), escape_actions)
+ , macro(macro)
+ , escape_actions(escape_actions)
         {
         }
 
- std::string operator()(iterator first, iterator last) const;
+ std::string operator()(iterator begin, iterator end) const;
 
         collector& temp;
         std::string const& source_mode;
- cpp_p_type cpp_p;
- python_p_type python_p;
- teletype_p_type teletype_p;
+ string_symbols const& macro;
+ actions& escape_actions;
     };
 
+
     struct code_action
     {
         // Does the actual syntax highlighing of code

Added: branches/quickbook-1.5-spirit2/detail/syntax_highlight.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/detail/syntax_highlight.cpp 2009-11-18 18:09:45 EST (Wed, 18 Nov 2009)
@@ -0,0 +1,68 @@
+#include "../syntax_highlight.hpp"
+#include "./actions_class.hpp"
+
+namespace quickbook
+{
+ typedef cpp_highlight<
+ span
+ , space
+ , string_symbols
+ , do_macro_action
+ , pre_escape_back
+ , post_escape_back
+ , actions
+ , unexpected_char
+ , collector>
+ cpp_p_type;
+
+ typedef python_highlight<
+ span
+ , space
+ , string_symbols
+ , do_macro_action
+ , pre_escape_back
+ , post_escape_back
+ , actions
+ , unexpected_char
+ , collector>
+ python_p_type;
+
+ typedef teletype_highlight<
+ plain_char_action
+ , string_symbols
+ , do_macro_action
+ , pre_escape_back
+ , post_escape_back
+ , actions
+ , collector>
+ teletype_p_type;
+
+ std::string syntax_highlight::operator()(iterator first, iterator last) const
+ {
+ // print the code with syntax coloring
+ if (source_mode == "c++")
+ {
+ cpp_p_type cpp_p(temp, macro, do_macro_action(temp), escape_actions);
+ parse(first, last, cpp_p);
+ }
+ else if (source_mode == "python")
+ {
+ python_p_type python_p(temp, macro, do_macro_action(temp), escape_actions);
+ parse(first, last, python_p);
+ }
+ else if (source_mode == "teletype")
+ {
+ teletype_p_type teletype_p(temp, macro, do_macro_action(temp), escape_actions);
+ parse(first, last, teletype_p);
+ }
+ else
+ {
+ BOOST_ASSERT(0);
+ }
+
+ std::string str;
+ temp.swap(str);
+
+ return str;
+ }
+}
\ No newline at end of file


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