Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71062 - in branches/quickbook-dev/tools/quickbook: src test/include
From: dnljms_at_[hidden]
Date: 2011-04-06 19:59:25


Author: danieljames
Date: 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
New Revision: 71062
URL: http://svn.boost.org/trac/boost/changeset/71062

Log:
Quickbook: Remove most of process suppression stuff.

Imports were failing because doc info expected values. The process_state
stuff is too fragile, so instead just process the contents of a
conditional phrase and discard them afterwards. Still suppresses all
elements.
Added:
   branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.gold (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.quickbook (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc1.quickbook (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc2.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 105 +++++++++++----------------------------
   branches/quickbook-dev/tools/quickbook/src/actions.hpp | 15 ----
   branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 20 ++++---
   branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 19 ++----
   branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp | 3
   branches/quickbook-dev/tools/quickbook/test/include/Jamfile.v2 | 1
   6 files changed, 53 insertions(+), 110 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -90,9 +90,9 @@
     void element_action::operator()(iterator first, iterator) const
     {
         value_consumer values = actions.values.release();
- if(!values.check()) return;
+ if(!values.check() || !actions.conditional) return;
         value v = values.consume();
- if(values.check()) return;
+ values.finish();
         
         switch(v.get_tag())
         {
@@ -177,7 +177,6 @@
     // Handles line-breaks (DEPRECATED!!!)
     void break_action::operator()(iterator first, iterator) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         file_position const pos = first.get_position();
@@ -226,7 +225,6 @@
 
     void block_action(quickbook::actions& actions, value block)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         detail::markup markup = detail::get_markup(block.get_tag());
@@ -238,7 +236,6 @@
 
     void block_empty_action(quickbook::actions& actions, value block)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         detail::markup markup = detail::get_markup(block.get_tag());
@@ -247,7 +244,6 @@
 
     void phrase_action(quickbook::actions& actions, value phrase)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.phrase);
 
         detail::markup markup = detail::get_markup(phrase.get_tag());
@@ -259,7 +255,6 @@
 
     void raw_phrase_action(quickbook::actions& actions, value phrase)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.phrase);
 
         detail::markup markup = detail::get_markup(phrase.get_tag());
@@ -268,8 +263,6 @@
 
     void paragraph_action::operator()() const
     {
- if(!(actions.process_state & actions.process_output)) return;
-
         std::string str;
         actions.phrase.swap(str);
 
@@ -303,8 +296,6 @@
 
     void header_action(quickbook::actions& actions, value heading_list)
     {
- if(!(actions.process_state & actions.process_output)) return;
-
         value_consumer values = heading_list;
 
         bool generic = heading_list.get_tag() == block_tags::generic_heading;
@@ -360,7 +351,6 @@
 
     void simple_phrase_action::operator()(char mark) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, out);
 
         int tag =
@@ -391,22 +381,35 @@
 
     bool cond_phrase_push::start()
     {
- saved_process_state = actions.process_state;
-
         value_consumer values = actions.values.release();
- bool condition = find(actions.macro,
- values.consume().get_quickbook().c_str());
 
- if (!condition)
- actions.process_state = actions.process_none;
+ saved_conditional = actions.conditional;
+
+ if (saved_conditional)
+ {
+ actions.conditional =
+ find(actions.macro, values.consume().get_quickbook().c_str());
+
+ if (!actions.conditional) {
+ actions.phrase.push();
+ actions.out.push();
+ actions.anchors.swap(anchors);
+ }
+ }
 
         return true;
     }
     
     void cond_phrase_push::cleanup()
     {
- actions.process_state =
- static_cast<quickbook::actions::process_flags>(saved_process_state);
+ if (saved_conditional && !actions.conditional)
+ {
+ actions.phrase.pop();
+ actions.out.pop();
+ actions.anchors.swap(anchors);
+ }
+
+ actions.conditional = saved_conditional;
     }
 
     namespace {
@@ -430,7 +433,6 @@
 
     void list_action(quickbook::actions& actions, value list)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         typedef std::pair<char, int> mark_type;
@@ -504,7 +506,6 @@
 
     void explicit_list_action(quickbook::actions& actions, value list)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         detail::markup markup = detail::get_markup(list.get_tag());
@@ -549,8 +550,6 @@
 
     void anchor_action(quickbook::actions& actions, value anchor)
     {
- if(!(actions.process_state & actions.process_output)) return;
-
         value_consumer values = anchor;
         actions.anchors.push_back(values.consume().get_quickbook());
         values.finish();
@@ -558,7 +557,6 @@
 
     void do_macro_action::operator()(std::string const& str) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         if (str == quickbook_get_date)
@@ -609,7 +607,6 @@
 
     void code_action::operator()(iterator first, iterator last) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, out);
 
         // preprocess the code section to remove the initial indentation
@@ -642,7 +639,6 @@
 
     void inline_code_action::operator()(iterator first, iterator last) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, out);
 
         std::string save;
@@ -660,7 +656,6 @@
 
     void raw_char_action::operator()(char ch) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         phrase << ch;
@@ -668,7 +663,6 @@
 
     void raw_char_action::operator()(iterator first, iterator /*last*/) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         phrase << *first;
@@ -676,7 +670,6 @@
 
     void plain_char_action::operator()(char ch) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         detail::print_char(ch, phrase.get());
@@ -684,7 +677,6 @@
 
     void plain_char_action::operator()(iterator first, iterator /*last*/) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         detail::print_char(*first, phrase.get());
@@ -692,7 +684,6 @@
 
     void escape_unicode_action::operator()(iterator first, iterator last) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, phrase);
 
         while(first != last && *first == '0') ++first;
@@ -714,7 +705,6 @@
 
     void image_action(quickbook::actions& actions, value image)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.phrase);
 
         typedef std::map<std::string, value> attribute_map;
@@ -892,8 +882,6 @@
 
     void macro_definition_action(quickbook::actions& actions, quickbook::value macro_definition)
     {
- if(!(actions.process_state & actions.process_macros)) return;
-
         value_consumer values = macro_definition;
         std::string macro_id = values.consume().get_quickbook();
         std::string phrase = values.consume().get_boostbook();
@@ -921,8 +909,6 @@
 
     void template_body_action(quickbook::actions& actions, quickbook::value template_definition)
     {
- if(!(actions.process_state & actions.process_templates)) return;
-
         value_consumer values = template_definition;
         std::string identifier = values.consume().get_quickbook();
 
@@ -1314,8 +1300,6 @@
     void do_template_action(quickbook::actions& actions, value template_list,
             file_position pos)
     {
- if(!(actions.process_state & actions.process_output)) return;
-
         // Get the arguments
         value_consumer values = template_list;
 
@@ -1369,7 +1353,6 @@
 
     void link_action(quickbook::actions& actions, value link)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.phrase);
 
         detail::markup markup = detail::get_markup(link.get_tag());
@@ -1393,7 +1376,6 @@
 
     void variable_list_action(quickbook::actions& actions, value variable_list)
     {
- if(!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         value_consumer values = variable_list;
@@ -1430,7 +1412,6 @@
 
     void table_action(quickbook::actions& actions, value table)
     {
- if(!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         value_consumer values = table;
@@ -1523,8 +1504,6 @@
 
     void begin_section_action(quickbook::actions& actions, value begin_section_list)
     {
- if(!(actions.process_state & actions.process_output)) return;
-
         value_consumer values = begin_section_list;
 
         value element_id = values.optional_consume(general_tags::element_id);
@@ -1576,7 +1555,6 @@
 
     void end_section_action(quickbook::actions& actions, value end_section, file_position pos)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         if (actions.section_level <= actions.min_section_level)
@@ -1722,7 +1700,6 @@
 
     void xinclude_action(quickbook::actions& actions, value xinclude)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         value_consumer values = xinclude;
@@ -1778,7 +1755,7 @@
                 actions.filename_relative.parent_path() / path);
         }
     }
-
+
     void load_quickbook(quickbook::actions& actions,
             include_search_return const& paths,
             value::tag_type load_type,
@@ -1789,21 +1766,17 @@
 
         // Check this before qbk_version_n gets changed by the inner file.
         bool keep_inner_source_mode = (qbk_version_n < 106);
-
+
         {
             file_state state(actions,
- load_type == block_tags::import ? file_state::scope_none :
- qbk_version_n >= 106u ? file_state::scope_all :
+ load_type == block_tags::import ? file_state::scope_output :
+ qbk_version_n >= 106u ? file_state::scope_callables :
                 file_state::scope_macros);
 
+ actions.imported = (load_type == block_tags::import);
             actions.filename = paths.filename;
             actions.filename_relative = paths.filename_relative;
 
- if (load_type == block_tags::import)
- actions.process_state =
- static_cast<quickbook::actions::process_flags>(
- actions.process_macros | actions.process_templates);
-
             // remain bug compatible with old versions of quickbook
             if(qbk_version_n < 106) actions.doc_id.clear();
 
@@ -1863,7 +1836,6 @@
 
     void include_action(quickbook::actions& actions, value include, file_position pos)
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.out);
 
         value_consumer values = include;
@@ -1875,6 +1847,9 @@
         try {
             if (qbk_version_n >= 106)
             {
+ if (actions.imported && include.get_tag() == block_tags::include)
+ return;
+
                 std::string ext = paths.filename.extension().generic_string();
                 
                 if (ext == ".qbk" || ext == ".quickbook")
@@ -1913,7 +1888,6 @@
     void phrase_to_docinfo_action_impl::operator()(iterator first, iterator last,
             value::tag_type tag) const
     {
- if (!(actions.process_state & actions.process_output)) return;
         write_anchors(actions, actions.phrase);
 
         std::string encoded;
@@ -1929,8 +1903,6 @@
     
     void to_value_action::operator()(iterator, iterator) const
     {
- if (!(actions.process_state & actions.process_output)) return;
-
         std::string value;
 
         if (!actions.out.str().empty())
@@ -1989,19 +1961,4 @@
     {
         actions_.context = saved_context_;
     }
-
- bool activate_processing_impl::start()
- {
- saved_process_state = actions.process_state;
- actions.process_state = actions.process_normal;
-
- return true;
- }
-
- void activate_processing_impl::cleanup()
- {
- actions.process_state =
- static_cast<quickbook::actions::process_flags>(saved_process_state);
- }
-
 }

Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -146,7 +146,8 @@
         void cleanup();
 
         quickbook::actions& actions;
- int saved_process_state;
+ bool saved_conditional;
+ std::vector<std::string> anchors;
     };
 
     struct span
@@ -410,18 +411,6 @@
         quickbook::actions& actions_;
         int saved_context_;
     };
-
- struct activate_processing_impl : scoped_action_base
- {
- activate_processing_impl(quickbook::actions& x)
- : actions(x) {}
-
- bool start();
- void cleanup();
-
- quickbook::actions& actions;
- int saved_process_state;
- };
 }
 
 #endif // BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -31,9 +31,10 @@
         , no_eols(true)
         , warned_about_breaks(false)
         , context(0)
+ , conditional(true)
 
+ , imported(false)
         , doc_type()
- , process_state(process_normal)
         , macro()
         , source_mode("c++")
         , doc_id()
@@ -58,7 +59,6 @@
         , scoped_output(*this)
         , scoped_no_eols(*this)
         , scoped_context(*this)
- , scoped_activate_processing(*this)
 
         , element(*this)
         , error(*this)
@@ -98,16 +98,20 @@
         : a(a)
         , scope(scope)
         , qbk_version(qbk_version_n)
+ , imported(a.imported)
         , doc_type(a.doc_type)
         , doc_id(a.doc_id)
         , filename(a.filename)
         , filename_relative(a.filename_relative)
         , source_mode(a.source_mode)
- , process_state(a.process_state)
         , macro()
     {
         if (scope & scope_macros) macro = a.macro;
         if (scope & scope_templates) a.templates.push();
+ if (scope & scope_output) {
+ a.out.push();
+ a.phrase.push();
+ }
         a.values.builder.save();
     }
 
@@ -115,12 +119,16 @@
     {
         a.values.builder.restore();
         boost::swap(qbk_version_n, qbk_version);
+ boost::swap(a.imported, imported);
         boost::swap(a.doc_type, doc_type);
         boost::swap(a.doc_id, doc_id);
         boost::swap(a.filename, filename);
         boost::swap(a.filename_relative, filename_relative);
         boost::swap(a.source_mode, source_mode);
- boost::swap(a.process_state, process_state);
+ if (scope & scope_output) {
+ a.out.pop();
+ a.phrase.pop();
+ }
         if (scope & scope_templates) a.templates.pop();
         if (scope & scope_macros) a.macro = macro;
     }
@@ -133,14 +141,10 @@
         , section_id(a.section_id)
         , qualified_section_id(a.qualified_section_id)
     {
- a.out.push();
- a.phrase.push();
     }
 
     template_state::~template_state()
     {
- a.phrase.pop();
- a.out.pop();
         boost::swap(a.template_depth, template_depth);
         boost::swap(a.section_level, section_level);
         boost::swap(a.min_section_level, min_section_level);

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -37,14 +37,6 @@
 
         static int const max_template_depth = 100;
         
- enum process_flags {
- process_none = 0,
- process_macros = 1,
- process_templates = 2,
- process_output = 4,
- process_normal = 7
- };
-
     // global state
         std::string doc_title_qbk;
         fs::path xinclude_base;
@@ -54,10 +46,11 @@
         bool no_eols;
         bool warned_about_breaks;
         int context;
+ bool conditional;
 
     // state saved for files and templates.
+ bool imported;
         std::string doc_type;
- process_flags process_state;
         string_symbols macro;
         std::string source_mode;
         std::string doc_id;
@@ -95,8 +88,6 @@
                                 scoped_no_eols;
         scoped_parser<scoped_context_impl>
                                 scoped_context;
- scoped_parser<activate_processing_impl>
- scoped_activate_processing;
 
         element_action element;
         error_action error;
@@ -126,7 +117,9 @@
             scope_none = 0,
             scope_macros = 1,
             scope_templates = 2,
- scope_all = 3
+ scope_output = 4,
+ scope_callables = scope_macros + scope_templates,
+ scope_all = scope_callables + scope_output
         };
     
         explicit file_state(actions&, scope_flags);
@@ -135,12 +128,12 @@
         quickbook::actions& a;
         scope_flags scope;
         unsigned qbk_version;
+ bool imported;
         std::string doc_type;
         std::string doc_id;
         fs::path filename;
         fs::path filename_relative;
         std::string source_mode;
- actions::process_flags process_state;
         string_symbols macro;
     private:
         file_state(file_state const&);

Modified: branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -126,8 +126,7 @@
                space
>> macro_identifier [actions.values.entry(ph::arg1, ph::arg2)]
>> blank
- >> actions.scoped_activate_processing()
- [ local.inner_phrase ]
+ >> local.inner_phrase
             ;
 
         local.identifier =

Modified: branches/quickbook-dev/tools/quickbook/test/include/Jamfile.v2
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/include/Jamfile.v2 (original)
+++ branches/quickbook-dev/tools/quickbook/test/include/Jamfile.v2 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -14,6 +14,7 @@
 import quickbook-testing : quickbook-test quickbook-error-test ;
 
 test-suite quickbook.test :
+ [ quickbook-test import-basic-1.6 ]
     [ quickbook-test filename ]
     [ quickbook-test filename-path : : : <quickbook-test-include>sub ]
     [ quickbook-test doc-title1-1.5 ]

Added: branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.gold
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.gold 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="import-1.6" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Import Quickbook Test</title>
+ <para>
+ Macro 1: import-basic-inc1.quickbook Template 1: import-basic-1.6.quickbook
+ </para>
+ <para>
+ Macro 2: import-basic-inc2.quickbook Template 2: import-basic-1.6.quickbook
+ </para>
+</article>

Added: branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/include/import-basic-1.6.quickbook 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -0,0 +1,12 @@
+[article Import Quickbook Test
+[quickbook 1.6]
+[id import-1.6]
+]
+
+[import import-basic-inc1.quickbook]
+
+macro1 [template1]
+
+[import import-basic-inc2.quickbook]
+
+macro2 [template2]

Added: branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc1.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc1.quickbook 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -0,0 +1,4 @@
+This shouldn't show: __FILENAME__
+
+[def macro1 Macro 1: __FILENAME__]
+[template template1 Template 1: __FILENAME__]
\ No newline at end of file

Added: branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc2.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/include/import-basic-inc2.quickbook 2011-04-06 19:59:24 EDT (Wed, 06 Apr 2011)
@@ -0,0 +1,10 @@
+[article Macro import.
+[quickbook 1.6]
+]
+
+[/ TOOD: Should I have a special docinfo type for this kind of thing? ]
+
+This shouldn't show: __FILENAME__
+
+[def macro2 Macro 2: __FILENAME__]
+[template template2 Template 2: __FILENAME__]
\ No newline at end of file


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