Boost logo

Boost-Commit :

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


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

Log:
Track the order of source mode tags.

So if there are two clashing source mode tags, then the latter one can
be used.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 4 ++--
   trunk/tools/quickbook/src/actions.hpp | 24 ++++++++++++++++++++++++
   trunk/tools/quickbook/src/doc_info_grammar.cpp | 8 ++++++--
   trunk/tools/quickbook/src/main_grammar.cpp | 15 +++++++++------
   trunk/tools/quickbook/src/state.cpp | 11 ++++++++++-
   trunk/tools/quickbook/src/state.hpp | 8 +++++++-
   trunk/tools/quickbook/src/state_save.hpp | 2 +-
   trunk/tools/quickbook/src/syntax_highlight.hpp | 35 +++++++++++++++++++++++++++++++++++
   8 files changed, 94 insertions(+), 13 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -686,7 +686,7 @@
 
     void source_mode_action(quickbook::state& state, value source_mode)
     {
- state.source_mode = source_mode.get_tag();
+ state.change_source_mode(source_mode.get_tag());
     }
 
     void next_source_mode_action(quickbook::state& state, value source_mode)
@@ -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;
+ state.source_mode_next : state.source_mode.source_mode;
         state.source_mode_next = 0;
 
         if (inline_code) {

Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/actions.hpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -315,6 +315,30 @@
             (l.*mf)(v);
         }
     };
+
+ // member_action_value
+ //
+ // Action for calling a unary member function with a fixed value.
+
+ template <typename T, typename Value>
+ struct member_action_fixed_value
+ {
+ typedef void(T::*member_function)(Value);
+
+ T& l;
+ member_function mf;
+ Value v;
+
+ member_action_fixed_value(T& l, member_function mf, Value v) : l(l), mf(mf), v(v) {}
+
+ void operator()() const {
+ (l.*mf)(v);
+ }
+
+ void operator()(parse_iterator first, parse_iterator last) const {
+ (l.*mf)(v);
+ }
+ };
 }
 
 #endif // BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP

Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -120,6 +120,10 @@
         plain_char_action plain_char(state);
         do_macro_action do_macro(state);
         scoped_parser<to_value_scoped_action> to_value(state);
+ member_action_value<quickbook::state, source_mode_type> change_source_mode(
+ state, &state::change_source_mode);
+ member_action_fixed_value<quickbook::state, source_mode_type> default_source_mode(
+ state, &state::change_source_mode, source_mode_tags::cpp);
         
         doc_info_details =
                 cl::eps_p [ph::var(local.source_mode_unset) = true]
@@ -148,7 +152,7 @@
                 ]
>> space
>> !(qbk_ver(106u) >> cl::eps_p(ph::var(local.source_mode_unset))
- [ph::var(state.source_mode) = source_mode_tags::cpp]
+ [default_source_mode]
                 )
>> ( *( ( local.doc_info_attribute
                         | local.doc_info_escaped_attributes
@@ -222,7 +226,7 @@
         local.attribute_rules[doc_attributes::compatibility_mode] = &local.doc_compatibility_mode;
 
         local.doc_source_mode = source_modes
- [ph::var(state.source_mode) = ph::arg1]
+ [change_source_mode]
                                             [ph::var(local.source_mode_unset) = false]
             ;
 

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

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/state.cpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -31,6 +31,7 @@
             string_stream& out_, document_state& document)
         : grammar_()
 
+ , order_pos(0)
         , xinclude_base(xinclude_base_)
 
         , templates()
@@ -46,7 +47,7 @@
 
         , imported(false)
         , macro()
- , source_mode(source_mode_tags::cpp)
+ , source_mode()
         , source_mode_next()
         , source_mode_next_pos()
         , current_file(0)
@@ -84,6 +85,10 @@
             = detail::encode_string(detail::path_to_generic(abstract_file_path));
     }
     
+ unsigned state::get_new_order_pos() {
+ return ++order_pos;
+ }
+
     void state::push_output() {
         out.push();
         phrase.push();
@@ -97,6 +102,10 @@
         in_list_save.pop();
     }
 
+ void state::change_source_mode(source_mode_type s) {
+ source_mode = source_mode_info(s, get_new_order_pos());
+ }
+
     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:10 2013 (r86662)
+++ trunk/tools/quickbook/src/state.hpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -18,6 +18,7 @@
 #include "template_stack.hpp"
 #include "symbols.hpp"
 #include "dependency_tracker.hpp"
+#include "syntax_highlight.hpp"
 
 namespace quickbook
 {
@@ -42,6 +43,7 @@
         static int const max_template_depth = 100;
 
     // global state
+ unsigned order_pos;
         fs::path xinclude_base;
         template_stack templates;
         int error_count;
@@ -57,7 +59,7 @@
     // state saved for files and templates.
         bool imported;
         string_symbols macro;
- source_mode_type source_mode;
+ source_mode_info source_mode;
         source_mode_type source_mode_next;
         value source_mode_next_pos;
         file_ptr current_file;
@@ -88,6 +90,8 @@
 
         void update_filename_macro();
 
+ unsigned get_new_order_pos();
+
         void push_output();
         void pop_output();
 
@@ -99,6 +103,8 @@
         void start_callouts();
         std::string add_callout(value);
         std::string end_callouts();
+
+ void change_source_mode(source_mode_type);
     };
 
     extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version

Modified: trunk/tools/quickbook/src/state_save.hpp
==============================================================================
--- trunk/tools/quickbook/src/state_save.hpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/state_save.hpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -40,7 +40,7 @@
         file_ptr current_file;
         fs::path abstract_file_path;
         fs::path xinclude_base;
- source_mode_type source_mode;
+ source_mode_info source_mode;
         string_symbols macro;
         int template_depth;
         int min_section_level;

Modified: trunk/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.hpp Tue Nov 12 15:33:10 2013 (r86662)
+++ trunk/tools/quickbook/src/syntax_highlight.hpp 2013-11-12 15:33:36 EST (Tue, 12 Nov 2013) (r86663)
@@ -10,9 +10,44 @@
 #define BOOST_QUICKBOOK_SYNTAX_HIGHLIGHT_HPP
 
 #include "fwd.hpp"
+#include "phrase_tags.hpp"
+#include <boost/swap.hpp>
 
 namespace quickbook
 {
+ //
+ // source_mode_info
+ //
+ // The source mode is stored in a few places, so the order needs to also be
+ // stored to work out which is the current source mode.
+
+ struct source_mode_info {
+ source_mode_type source_mode;
+ unsigned order;
+
+ source_mode_info() : source_mode(source_mode_tags::cpp), order(0) {}
+
+ source_mode_info(source_mode_type source_mode, unsigned order) :
+ source_mode(source_mode),
+ order(order) {}
+
+ void update(source_mode_info const& x) {
+ if (x.order > order) {
+ source_mode = x.source_mode;
+ order = x.order;
+ }
+ }
+
+ void swap(source_mode_info& x) {
+ boost::swap(source_mode, x.source_mode);
+ boost::swap(order, x.order);
+ }
+ };
+
+ inline void swap(source_mode_info& x, source_mode_info& y) {
+ x.swap(y);
+ }
+
     void syntax_highlight(
         parse_iterator first, parse_iterator last,
         quickbook::state& state,


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