Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65028 - in trunk/tools/quickbook: . detail
From: dnljms_at_[hidden]
Date: 2010-08-26 16:54:15


Author: danieljames
Date: 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
New Revision: 65028
URL: http://svn.boost.org/trac/boost/changeset/65028

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

Modified: trunk/tools/quickbook/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/Jamfile.v2 (original)
+++ trunk/tools/quickbook/Jamfile.v2 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
@@ -27,6 +27,7 @@
     detail/collector.cpp
     detail/template_stack.cpp
     detail/markups.cpp
+ detail/syntax_highlight.cpp
     /boost//program_options
     /boost//filesystem
     : #<define>QUICKBOOK_NO_DATES

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
@@ -359,32 +359,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: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
@@ -20,7 +20,6 @@
 #include <boost/filesystem/v2/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;
@@ -467,40 +468,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
     {
@@ -511,21 +478,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: trunk/tools/quickbook/detail/syntax_highlight.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/detail/syntax_highlight.cpp 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
@@ -0,0 +1,77 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#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

Modified: trunk/tools/quickbook/phrase.hpp
==============================================================================
--- trunk/tools/quickbook/phrase.hpp (original)
+++ trunk/tools/quickbook/phrase.hpp 2010-08-26 16:54:12 EDT (Thu, 26 Aug 2010)
@@ -18,6 +18,7 @@
 #include <boost/spirit/include/classic_assign_actor.hpp>
 #include <boost/spirit/include/classic_clear_actor.hpp>
 #include <boost/spirit/include/classic_if.hpp>
+#include <boost/spirit/include/classic_loops.hpp>
 
 namespace quickbook
 {


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