Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86664 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-11-12 15:33:59


Author: danieljames
Date: 2013-11-12 15:33:59 EST (Tue, 12 Nov 2013)
New Revision: 86664
URL: http://svn.boost.org/trac/boost/changeset/86664

Log:
Stack tagged source modes.

For when one tagged element is inside another.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 2 +-
   trunk/tools/quickbook/src/main_grammar.cpp | 15 ++++++---------
   trunk/tools/quickbook/src/state.cpp | 21 +++++++++++++++++++++
   trunk/tools/quickbook/src/state.hpp | 5 +++++
   4 files changed, 33 insertions(+), 10 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Nov 12 15:33:36 2013 (r86663)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-12 15:33:59 EST (Tue, 12 Nov 2013) (r86664)
@@ -710,7 +710,7 @@
         bool block = code_tag != code_tags::inline_code;
 
         source_mode_type source_mode = state.source_mode_next ?
- state.source_mode_next : state.source_mode.source_mode;
+ state.source_mode_next : state.current_source_mode().source_mode;
         state.source_mode_next = 0;
 
         if (inline_code) {

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Tue Nov 12 15:33:36 2013 (r86663)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-11-12 15:33:59 EST (Tue, 12 Nov 2013) (r86664)
@@ -152,8 +152,7 @@
 
     struct process_element_impl : scoped_action_base {
         process_element_impl(main_grammar_local& l) :
- l(l), changed_source_mode_(false), saved_source_mode_(),
- element_context_error_(false) {}
+ l(l), pushed_source_mode_(false), element_context_error_(false) {}
 
         bool start()
         {
@@ -186,9 +185,8 @@
             if (l.state_.source_mode_next &&
                 info_.type != element_info::maybe_block)
             {
- saved_source_mode_ = l.state_.source_mode;
- l.state_.change_source_mode(l.state_.source_mode_next);
- changed_source_mode_ = true;
+ l.state_.push_tagged_source_mode(l.state_.source_mode_next);
+ pushed_source_mode_ = true;
                 l.state_.source_mode_next = 0;
             }
 
@@ -225,14 +223,13 @@
         void failure() { l.element_type = element_info::nothing; }
 
         void cleanup() {
- if (changed_source_mode_)
- boost::swap(l.state_.source_mode, saved_source_mode_);
+ if (pushed_source_mode_)
+ l.state_.pop_tagged_source_mode();
         }
 
         main_grammar_local& l;
         element_info info_;
- bool changed_source_mode_;
- source_mode_info saved_source_mode_;
+ bool pushed_source_mode_;
         bool element_context_error_;
     };
 

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Tue Nov 12 15:33:36 2013 (r86663)
+++ trunk/tools/quickbook/src/state.cpp 2013-11-12 15:33:59 EST (Tue, 12 Nov 2013) (r86664)
@@ -15,6 +15,7 @@
 #include "native_text.hpp"
 #include "utils.hpp"
 #include "phrase_tags.hpp"
+#include <boost/foreach.hpp>
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -102,10 +103,30 @@
         in_list_save.pop();
     }
 
+ source_mode_info state::current_source_mode() const {
+ source_mode_info result = source_mode;
+
+ BOOST_FOREACH(source_mode_info const& s, tagged_source_mode_stack) {
+ result.update(s);
+ }
+
+ return result;
+ }
+
     void state::change_source_mode(source_mode_type s) {
         source_mode = source_mode_info(s, get_new_order_pos());
     }
 
+ void state::push_tagged_source_mode(source_mode_type s) {
+ tagged_source_mode_stack.push_back(
+ source_mode_info(s, get_new_order_pos()));
+ }
+
+ void state::pop_tagged_source_mode() {
+ assert(!tagged_source_mode_stack.empty());
+ tagged_source_mode_stack.pop_back();
+ }
+
     state_save::state_save(quickbook::state& state, scope_flags scope)
         : state(state)
         , scope(scope)

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Tue Nov 12 15:33:36 2013 (r86663)
+++ trunk/tools/quickbook/src/state.hpp 2013-11-12 15:33:59 EST (Tue, 12 Nov 2013) (r86664)
@@ -62,6 +62,8 @@
         source_mode_info source_mode;
         source_mode_type source_mode_next;
         value source_mode_next_pos;
+ std::vector<source_mode_info>
+ tagged_source_mode_stack;
         file_ptr current_file;
 
         // A machine independent representation of the current file's
@@ -104,7 +106,10 @@
         std::string add_callout(value);
         std::string end_callouts();
 
+ source_mode_info current_source_mode() const;
         void change_source_mode(source_mode_type);
+ void push_tagged_source_mode(source_mode_type);
+ void pop_tagged_source_mode();
     };
 
     extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version


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