Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65358 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2010-09-08 20:10:34


Author: danieljames
Date: 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
New Revision: 65358
URL: http://svn.boost.org/trac/boost/changeset/65358

Log:
Cherry pick some reorganisation from the spirit 2 branch.

Based on [57774], [59562], [58046], [59566].
Added:
   trunk/tools/quickbook/src/fwd.hpp (contents, props changed)
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 8 ++
   trunk/tools/quickbook/src/actions.hpp | 84 +++++++++++++++++++--------------------
   trunk/tools/quickbook/src/actions_class.cpp | 11 +---
   trunk/tools/quickbook/src/actions_class.hpp | 2
   trunk/tools/quickbook/src/block_grammar.cpp | 1
   trunk/tools/quickbook/src/doc_info_grammar.cpp | 1
   trunk/tools/quickbook/src/grammar.hpp | 2
   trunk/tools/quickbook/src/phrase_grammar.hpp | 1
   trunk/tools/quickbook/src/quickbook.cpp | 3 -
   trunk/tools/quickbook/src/quickbook.hpp | 38 +++++------------
   trunk/tools/quickbook/src/syntax_highlight.cpp | 13 ++++-
   11 files changed, 71 insertions(+), 93 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -26,6 +26,10 @@
     char const* quickbook_get_date = "__quickbook_get_date__";
     char const* quickbook_get_time = "__quickbook_get_time__";
 
+ int qbk_major_version = -1;
+ int qbk_minor_version = -1;
+ unsigned qbk_version_n = 0; // qbk_major_version * 100 + qbk_minor_version
+
     namespace {
         std::string fully_qualified_id(std::string const& library_id,
             std::string const& qualified_section_id,
@@ -371,7 +375,7 @@
         phrase.swap(save);
 
         // print the code with syntax coloring
- std::string str = syntax_p(first_, last_);
+ std::string str = syntax_highlight(first_, last_, actions, actions.source_mode);
 
         phrase.swap(save);
 
@@ -390,7 +394,7 @@
         out.swap(save);
 
         // print the code with syntax coloring
- std::string str = syntax_p(first, last);
+ std::string str = syntax_highlight(first, last, actions, actions.source_mode);
 
         out.swap(save);
 

Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -10,16 +10,15 @@
 #if !defined(BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP)
 #define BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP
 
-#include <time.h>
 #include <map>
 #include <string>
 #include <vector>
 #include <stack>
 #include <algorithm>
-#include <boost/spirit/include/classic_iterator.hpp>
 #include <boost/filesystem/v2/operations.hpp>
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
+#include "fwd.hpp"
 #include "collector.hpp"
 #include "template_stack.hpp"
 #include "utils.hpp"
@@ -35,24 +34,44 @@
     namespace cl = boost::spirit::classic;
     namespace fs = boost::filesystem;
 
- typedef cl::position_iterator<std::string::const_iterator,
- cl::file_position_base<char const*> > iterator;
- typedef cl::file_position_base<char const*> position;
+ extern int qbk_major_version;
+ extern int qbk_minor_version;
+ extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version
+
+ struct quickbook_range {
+ template <typename Arg>
+ struct result
+ {
+ typedef bool type;
+ };
+
+ quickbook_range(unsigned min_, unsigned max_)
+ : min_(min_), max_(max_) {}
+
+ bool operator()() const {
+ return qbk_version_n >= min_ && qbk_version_n < max_;
+ }
+
+ unsigned min_, max_;
+ };
+
+ inline quickbook_range qbk_since(unsigned min_) {
+ return quickbook_range(min_, 999);
+ }
+
+ inline quickbook_range qbk_before(unsigned max_) {
+ return quickbook_range(0, max_);
+ }
+
     typedef cl::symbols<std::string> string_symbols;
     typedef std::map<std::string, std::string> attribute_map;
 
- struct actions;
- extern tm* current_time; // the current time
- extern tm* current_gm_time; // the current UTC time
- extern bool debug_mode;
- extern std::vector<std::string> include_path;
- extern std::vector<std::string> preset_defines;
-
- // forward declarations
- struct actions;
- int parse_file(char const* filein_, actions& actor, bool ignore_docinfo = false);
     int load_snippets(std::string const& file, std::vector<template_symbol>& storage,
         std::string const& extension, std::string const& doc_id);
+ std::string syntax_highlight(
+ iterator first, iterator last,
+ actions& escape_actions,
+ std::string const& source_mode);
 
     struct error_action
     {
@@ -473,29 +492,6 @@
         std::string str;
     };
     
- 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)
- , macro(macro)
- , escape_actions(escape_actions)
- {
- }
-
- std::string operator()(iterator begin, iterator end) const;
-
- collector& temp;
- std::string const& source_mode;
- string_symbols const& macro;
- actions& escape_actions;
- };
-
-
     struct code_action
     {
         // Does the actual syntax highlighing of code
@@ -503,10 +499,10 @@
         code_action(
             collector& out
           , collector& phrase
- , syntax_highlight& syntax_p)
+ , quickbook::actions& actions)
         : out(out)
         , phrase(phrase)
- , syntax_p(syntax_p)
+ , actions(actions)
         {
         }
 
@@ -514,7 +510,7 @@
 
         collector& out;
         collector& phrase;
- syntax_highlight& syntax_p;
+ quickbook::actions& actions;
     };
 
     struct inline_code_action
@@ -523,15 +519,15 @@
 
         inline_code_action(
             collector& out
- , syntax_highlight& syntax_p)
+ , quickbook::actions& actions)
         : out(out)
- , syntax_p(syntax_p)
+ , actions(actions)
         {}
 
         void operator()(iterator first, iterator last) const;
 
         collector& out;
- syntax_highlight& syntax_p;
+ quickbook::actions& actions;
     };
 
     struct start_varlistitem_action

Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp (original)
+++ trunk/tools/quickbook/src/actions_class.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -10,6 +10,7 @@
 =============================================================================*/
 #include "actions_class.hpp"
 #include "markups.hpp"
+#include "quickbook.hpp"
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -37,7 +38,6 @@
 
     // auxilliary streams
         , phrase()
- , temp()
         , list_buffer()
 
     // state
@@ -82,10 +82,9 @@
         , extract_name_first(name.first, phrase)
         , extract_doc_last_revision(doc_last_revision, phrase)
         , extract_doc_category(doc_category, phrase)
- , syntax_p(temp, source_mode, macro, *this)
- , code(out, phrase, syntax_p)
- , code_block(phrase, phrase, syntax_p)
- , inline_code(phrase, syntax_p)
+ , code(out, phrase, *this)
+ , code_block(phrase, phrase, *this)
+ , inline_code(phrase, *this)
         , inside_paragraph(temp_para, phrase, paragraph_pre, paragraph_post)
         , write_paragraphs(out, temp_para)
         , h(out, phrase, element_id, doc_id, section_id, qualified_section_id, section_level)
@@ -221,7 +220,6 @@
 
         out.push();
         phrase.push();
- temp.push();
         temp_para.push();
         list_buffer.push();
         templates.push();
@@ -263,7 +261,6 @@
 
         out.pop();
         phrase.pop();
- temp.pop();
         temp_para.pop();
         list_buffer.pop();
         templates.pop();

Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp (original)
+++ trunk/tools/quickbook/src/actions_class.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -61,7 +61,6 @@
 
     // auxilliary streams
         collector phrase;
- collector temp;
         collector temp_para;
         collector list_buffer;
 
@@ -134,7 +133,6 @@
         phrase_to_docinfo_action extract_doc_last_revision;
         phrase_to_docinfo_action extract_doc_category;
 
- syntax_highlight syntax_p;
         code_action code;
         code_action code_block;
         inline_code_action inline_code;

Modified: trunk/tools/quickbook/src/block_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/block_grammar.cpp (original)
+++ trunk/tools/quickbook/src/block_grammar.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -9,7 +9,6 @@
 =============================================================================*/
 
 #include "phrase_grammar.hpp"
-#include "quickbook.hpp"
 #include "utils.hpp"
 #include "actions_class.hpp"
 #include <boost/spirit/include/classic_confix.hpp>

Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -9,7 +9,6 @@
 =============================================================================*/
 
 #include "phrase_grammar.hpp"
-#include "quickbook.hpp"
 #include "actions_class.hpp"
 #include <boost/spirit/include/classic_core.hpp>
 #include <boost/spirit/include/classic_actor.hpp>

Added: trunk/tools/quickbook/src/fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/fwd.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -0,0 +1,27 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_FWD_HPP)
+#define BOOST_SPIRIT_FWD_HPP
+
+#include <boost/spirit/include/classic_iterator.hpp>
+#include <boost/range.hpp>
+#include <boost/shared_ptr.hpp>
+
+namespace quickbook
+{
+ struct actions;
+
+ typedef boost::spirit::classic::file_position_base<char const*> position;
+ typedef boost::spirit::classic::position_iterator<
+ std::string::const_iterator, position> iterator;
+}
+
+#endif
\ No newline at end of file

Modified: trunk/tools/quickbook/src/grammar.hpp
==============================================================================
--- trunk/tools/quickbook/src/grammar.hpp (original)
+++ trunk/tools/quickbook/src/grammar.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -11,7 +11,7 @@
 #define BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP
 
 #include <boost/spirit/include/classic_core.hpp>
-#include "actions.hpp"
+#include "fwd.hpp"
 
 namespace quickbook
 {

Modified: trunk/tools/quickbook/src/phrase_grammar.hpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_grammar.hpp (original)
+++ trunk/tools/quickbook/src/phrase_grammar.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -12,7 +12,6 @@
 
 #include "grammar.hpp"
 #include "actions_class.hpp"
-#include "quickbook.hpp"
 #include "utils.hpp"
 #include <boost/spirit/include/classic_core.hpp>
 #include <boost/spirit/include/classic_confix.hpp>

Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -38,9 +38,6 @@
     tm* current_time; // the current time
     tm* current_gm_time; // the current UTC time
     bool debug_mode; // for quickbook developers only
- int qbk_major_version = -1;
- int qbk_minor_version = -1;
- unsigned qbk_version_n = 0; // qbk_major_version * 100 + qbk_minor_version
     bool ms_errors = false; // output errors/warnings as if for VS
     std::vector<std::string> include_path;
     std::vector<std::string> preset_defines;

Modified: trunk/tools/quickbook/src/quickbook.hpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.hpp (original)
+++ trunk/tools/quickbook/src/quickbook.hpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -12,36 +12,20 @@
 #if !defined(BOOST_SPIRIT_QUICKBOOK_QUICKBOOK_HPP)
 #define BOOST_SPIRIT_QUICKBOOK_QUICKBOOK_HPP
 
+#include <time.h>
+#include <vector>
+#include <string>
+#include "fwd.hpp"
+
 namespace quickbook
 {
- extern int qbk_major_version;
- extern int qbk_minor_version;
- extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version
-
- struct quickbook_range {
- template <typename Arg>
- struct result
- {
- typedef bool type;
- };
-
- quickbook_range(unsigned min_, unsigned max_)
- : min_(min_), max_(max_) {}
-
- bool operator()() const {
- return qbk_version_n >= min_ && qbk_version_n < max_;
- }
+ extern tm* current_time; // the current time
+ extern tm* current_gm_time; // the current UTC time
+ extern bool debug_mode;
+ extern std::vector<std::string> include_path;
+ extern std::vector<std::string> preset_defines;
 
- unsigned min_, max_;
- };
-
- inline quickbook_range qbk_since(unsigned min_) {
- return quickbook_range(min_, 999);
- }
-
- inline quickbook_range qbk_before(unsigned max_) {
- return quickbook_range(0, max_);
- }
+ int parse_file(char const* filein_, actions& actor, bool ignore_docinfo = false);
 }
 
 #endif

Modified: trunk/tools/quickbook/src/syntax_highlight.cpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.cpp (original)
+++ trunk/tools/quickbook/src/syntax_highlight.cpp 2010-09-08 20:10:30 EDT (Wed, 08 Sep 2010)
@@ -43,22 +43,27 @@
       , collector>
     teletype_p_type;
     
- std::string syntax_highlight::operator()(iterator first, iterator last) const
+ std::string syntax_highlight(
+ iterator first, iterator last,
+ actions& escape_actions,
+ std::string const& source_mode)
     {
+ quickbook::collector temp;
+
         // print the code with syntax coloring
         if (source_mode == "c++")
         {
- cpp_p_type cpp_p(temp, macro, do_macro_action(temp), escape_actions);
+ cpp_p_type cpp_p(temp, escape_actions.macro, do_macro_action(temp), escape_actions);
             boost::spirit::classic::parse(first, last, cpp_p);
         }
         else if (source_mode == "python")
         {
- python_p_type python_p(temp, macro, do_macro_action(temp), escape_actions);
+ python_p_type python_p(temp, escape_actions.macro, do_macro_action(temp), escape_actions);
             boost::spirit::classic::parse(first, last, python_p);
         }
         else if (source_mode == "teletype")
         {
- teletype_p_type teletype_p(temp, macro, do_macro_action(temp), escape_actions);
+ teletype_p_type teletype_p(temp, escape_actions.macro, do_macro_action(temp), escape_actions);
             boost::spirit::classic::parse(first, last, teletype_p);
         }
         else


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