Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85339 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-08-13 18:21:39


Author: danieljames
Date: 2013-08-13 18:21:39 EDT (Tue, 13 Aug 2013)
New Revision: 85339
URL: http://svn.boost.org/trac/boost/changeset/85339

Log:
Make list generation state part of the output state.

Which sounds obvious when it's put like that. But I originally did this
in the parser because the parser was tracking lists anyway. But that
made a mess of handling `[ordered_list]` and `[itemized_list]`, I tried
fixing that but made a pig's ear of it.

The code for handling 'explicit lists' will still be a bit messy because
the generator is currently oblivious to what type of block element it's
generating markup for, and it needs to be aware for lists.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 1 +
   trunk/tools/quickbook/src/main_grammar.cpp | 9 +++++----
   trunk/tools/quickbook/src/state.cpp | 7 ++++++-
   trunk/tools/quickbook/src/state.hpp | 4 +++-
   4 files changed, 15 insertions(+), 6 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Aug 13 18:21:17 2013 (r85338)
+++ trunk/tools/quickbook/src/actions.cpp 2013-08-13 18:21:39 EDT (Tue, 13 Aug 2013) (r85339)
@@ -531,6 +531,7 @@
         assert(mark == '*' || mark == '#');
         push_output();
         out << ((mark == '#') ? "<orderedlist>\n" : "<itemizedlist>\n");
+ in_list = true;
     }
 
     void state::end_list(char mark)

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Tue Aug 13 18:21:17 2013 (r85338)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-08-13 18:21:39 EDT (Tue, 13 Aug 2013) (r85339)
@@ -170,13 +170,10 @@
 
         void push_list_item(list_stack_item const& item) {
             list_stack.push(item);
- state_.in_list = list_stack.top().type & list_stack_item::is_list;
         }
 
         void pop_list_item() {
             list_stack.pop();
- state_.in_list = !list_stack.empty() &&
- list_stack.top().type & list_stack_item::is_list;
         }
     };
 
@@ -270,7 +267,8 @@
             l(l) {}
 
         bool operator()() const {
- return l.state_.in_list;
+ return !l.list_stack.empty() &&
+ l.list_stack.top().type & list_stack_item::is_list;
         }
     };
 
@@ -1054,11 +1052,14 @@
     void main_grammar_local::start_blocks_impl(parse_iterator, parse_iterator)
     {
         push_list_item(list_stack_item(list_stack_item::top_level));
+ state_.in_list = false; // TODO: Is this right? Should already be false, but
+ // not for templates in lists?
     }
 
     void main_grammar_local::start_nested_blocks_impl(parse_iterator, parse_iterator)
     {
         bool explicit_list = state_.explicit_list;
+ state_.in_list = explicit_list;
         state_.explicit_list = false;
 
         push_list_item(list_stack_item(explicit_list ?

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Tue Aug 13 18:21:17 2013 (r85338)
+++ trunk/tools/quickbook/src/state.cpp 2013-08-13 18:21:39 EDT (Tue, 13 Aug 2013) (r85339)
@@ -41,7 +41,6 @@
         , callout_depth(0)
         , dependencies()
         , explicit_list(false)
- , in_list(false)
 
         , imported(false)
         , macro()
@@ -53,8 +52,11 @@
         , template_depth(0)
         , min_section_level(1)
 
+ , in_list(false)
+ , in_list_save()
         , out(out_)
         , phrase()
+
         , values(&current_file)
     {
         // add the predefined macros
@@ -76,11 +78,14 @@
     void state::push_output() {
         out.push();
         phrase.push();
+ in_list_save.push(in_list);
     }
 
     void state::pop_output() {
         phrase.pop();
         out.pop();
+ in_list = in_list_save.top();
+ in_list_save.pop();
     }
 
     state_save::state_save(quickbook::state& state, scope_flags scope)

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Tue Aug 13 18:21:17 2013 (r85338)
+++ trunk/tools/quickbook/src/state.hpp 2013-08-13 18:21:39 EDT (Tue, 13 Aug 2013) (r85339)
@@ -53,7 +53,6 @@
         int callout_depth; // they don't nest.
         dependency_tracker dependencies;
         bool explicit_list; // set when using a list
- bool in_list;
 
     // state saved for files and templates.
         bool imported;
@@ -70,6 +69,9 @@
         int min_section_level;
 
     // output state - scoped by templates and grammar
+ bool in_list; // generating a list
+ std::stack<bool> in_list_save; // save the in_list state
+ // TODO: Something better...
         collector out; // main output stream
         collector phrase; // phrase output stream
 


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