Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67634 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-01-03 17:11:50


Author: danieljames
Date: 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
New Revision: 67634
URL: http://svn.boost.org/trac/boost/changeset/67634

Log:
Use a single grammar.

Speeds up quickbook a fair bit, hopefully will make up for the anchors
change which was quite costly.
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 6 ++----
   trunk/tools/quickbook/src/actions_class.cpp | 15 +++++++++++++--
   trunk/tools/quickbook/src/actions_class.hpp | 6 ++++++
   trunk/tools/quickbook/src/fwd.hpp | 1 +
   trunk/tools/quickbook/src/quickbook.cpp | 10 ++++------
   trunk/tools/quickbook/src/syntax_highlight.hpp | 12 ++++++------
   6 files changed, 32 insertions(+), 18 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -813,15 +813,13 @@
             }
             else
             {
- quickbook_grammar g(actions);
-
                 if (!body.is_block)
                 {
                     // do a phrase level parse
                     iterator first(body.content.begin(), body.content.end(),
                         position(body.position.file.c_str(), body.position.line, body.position.column));
                     iterator last(body.content.end(), body.content.end());
- return cl::parse(first, last, g.simple_phrase).full;
+ return cl::parse(first, last, actions.grammar().simple_phrase).full;
                 }
                 else
                 {
@@ -833,7 +831,7 @@
                     iterator first(content.begin(), content.end(),
                         position(body.position.file.c_str(), body.position.line, body.position.column));
                     iterator last(content.end(), content.end());
- return cl::parse(first, last, g.block).full;
+ return cl::parse(first, last, actions.grammar().block).full;
                 }
             }
         }

Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp (original)
+++ trunk/tools/quickbook/src/actions_class.cpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -11,6 +11,7 @@
 #include "actions_class.hpp"
 #include "markups.hpp"
 #include "quickbook.hpp"
+#include "grammar.hpp"
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -19,8 +20,10 @@
 namespace quickbook
 {
     actions::actions(char const* filein_, fs::path const& outdir_, string_stream& out_)
+ : grammar_()
+
     // header info
- : doc_type()
+ , doc_type()
         , doc_title()
         , doc_version()
         , doc_id()
@@ -210,8 +213,12 @@
             ("__TIME__", std::string(quickbook_get_time))
             ("__FILENAME__", filename_str)
         ;
+
+ boost::scoped_ptr<quickbook_grammar> g(
+ new quickbook_grammar(*this));
+ grammar_.swap(g);
     }
-
+
     void actions::push()
     {
         state_stack.push(
@@ -272,4 +279,8 @@
         list_buffer.pop();
         templates.pop();
     }
+
+ quickbook_grammar& actions::grammar() const {
+ return *grammar_;
+ }
 }

Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp (original)
+++ trunk/tools/quickbook/src/actions_class.hpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -13,6 +13,7 @@
 #include "actions.hpp"
 #include "scoped_parser.hpp"
 #include <boost/tuple/tuple.hpp>
+#include <boost/scoped_ptr.hpp>
 
 namespace quickbook
 {
@@ -23,6 +24,10 @@
     {
         actions(char const* filein_, fs::path const& outdir, string_stream& out_);
 
+ private:
+ boost::scoped_ptr<quickbook_grammar> grammar_;
+
+ public:
     ///////////////////////////////////////////////////////////////////////////
     // State
     ///////////////////////////////////////////////////////////////////////////
@@ -124,6 +129,7 @@
         void copy_macros_for_write();
         void push();
         void pop();
+ quickbook_grammar& grammar() const;
 
     ///////////////////////////////////////////////////////////////////////////
     // actions

Modified: trunk/tools/quickbook/src/fwd.hpp
==============================================================================
--- trunk/tools/quickbook/src/fwd.hpp (original)
+++ trunk/tools/quickbook/src/fwd.hpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -18,6 +18,7 @@
 namespace quickbook
 {
     struct actions;
+ struct quickbook_grammar;
 
     typedef boost::spirit::classic::file_position_base<char const*> position;
     typedef boost::spirit::classic::position_iterator<

Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -44,8 +44,6 @@
 
     static void set_macros(actions& actor)
     {
- quickbook_grammar g(actor);
-
         for(std::vector<std::string>::const_iterator
                 it = preset_defines.begin(),
                 end = preset_defines.end();
@@ -54,7 +52,7 @@
             iterator first(it->begin(), it->end(), "command line parameter");
             iterator last(it->end(), it->end());
 
- cl::parse(first, last, g.command_line_macro);
+ cl::parse(first, last, actor.grammar().command_line_macro);
             // TODO: Check result?
         }
     }
@@ -81,14 +79,13 @@
         iterator first(storage.begin(), storage.end(), filein_);
         iterator last(storage.end(), storage.end());
 
- quickbook_grammar g(actor);
- cl::parse_info<iterator> info = cl::parse(first, last, g.doc_info);
+ cl::parse_info<iterator> info = cl::parse(first, last, actor.grammar().doc_info);
 
         if (info.hit || ignore_docinfo)
         {
             pre(actor.out, actor, ignore_docinfo);
 
- info = cl::parse(info.hit ? info.stop : first, last, g.block);
+ info = cl::parse(info.hit ? info.stop : first, last, actor.grammar().block);
             if (info.full)
             {
                 post(actor.out, actor, ignore_docinfo);
@@ -110,6 +107,7 @@
     parse_document(char const* filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false)
     {
         actions actor(filein_, outdir, out);
+
         set_macros(actor);
         bool r = parse_file(filein_, actor);
         if (actor.section_level != 0)

Modified: trunk/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.hpp (original)
+++ trunk/tools/quickbook/src/syntax_highlight.hpp 2011-01-03 17:11:44 EST (Mon, 03 Jan 2011)
@@ -41,7 +41,7 @@
         struct definition
         {
             definition(cpp_highlight const& self)
- : g(self.escape_actions)
+ : g(self.escape_actions.grammar())
             {
                 program
                     =
@@ -157,7 +157,7 @@
                             string_char;
 
             cl::symbols<> keyword_;
- quickbook_grammar g;
+ quickbook_grammar& g;
             std::string save;
 
             cl::rule<Scanner> const&
@@ -192,7 +192,7 @@
         struct definition
         {
             definition(python_highlight const& self)
- : g(self.escape_actions)
+ : g(self.escape_actions.grammar())
             {
                 program
                     =
@@ -313,7 +313,7 @@
                             qbk_phrase, escape, string_char;
 
             cl::symbols<> keyword_;
- quickbook_grammar g;
+ quickbook_grammar& g;
             std::string save;
 
             cl::rule<Scanner> const&
@@ -344,7 +344,7 @@
         struct definition
         {
             definition(teletype_highlight const& self)
- : g(self.escape_actions)
+ : g(self.escape_actions.grammar())
             {
                 program
                     =
@@ -390,7 +390,7 @@
 
             cl::rule<Scanner> program, macro, qbk_phrase, escape;
 
- quickbook_grammar g;
+ quickbook_grammar& g;
             std::string save;
 
             cl::rule<Scanner> const&


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