Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69178 - in branches/quickbook-filenames/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-02-22 15:41:45


Author: danieljames
Date: 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
New Revision: 69178
URL: http://svn.boost.org/trac/boost/changeset/69178

Log:
Use values for lists.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 158 +++++++++++++++++++--------------------
   branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 81 --------------------
   branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 9 --
   branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 8 --
   branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp | 3
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 45 ++++++----
   branches/quickbook-filenames/tools/quickbook/test/list_test.gold | 29 +++++++
   branches/quickbook-filenames/tools/quickbook/test/list_test.quickbook | 7 +
   8 files changed, 141 insertions(+), 199 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -50,6 +50,7 @@
         }
     }
 
+ void list_action(quickbook::actions&, value);
     void header_action(quickbook::actions&, value);
     void begin_section_action(quickbook::actions&, value);
     void end_section_action(quickbook::actions&, value, file_position);
@@ -76,6 +77,8 @@
         
         switch(v.get_tag())
         {
+ case block_tags::list:
+ return list_action(actions, v);
         case block_tags::generic_heading:
         case block_tags::heading1:
         case block_tags::heading2:
@@ -203,15 +206,6 @@
         assert(!values.is());
     }
 
- void phrase_action::operator()() const
- {
- if(!actions.output_pre(phrase)) return;
-
- std::string str;
- phrase.swap(str);
- out << pre << str << post;
- }
-
     void phrase_action_(quickbook::actions& actions, value phrase)
     {
         if(!actions.output_pre(actions.phrase)) return;
@@ -348,98 +342,98 @@
         actions.suppress = saved_suppress;
     }
 
- void list_action::operator()(iterator first, iterator last) const
- {
- if(actions.suppress) return;
-
- BOOST_ASSERT(!list_marks.empty()); // there must be at least one item in the stack
- out << list_buffer.str();
- list_buffer.clear();
-
- while (!list_marks.empty())
+ namespace {
+ int indent_length(std::string const& indent)
         {
- char mark = list_marks.top().first;
- list_marks.pop();
- out << std::string((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
- if (list_marks.size() >= 1)
- out << "</listitem>";
+ int length = 0;
+ for(std::string::const_iterator
+ first = indent.begin(), end = indent.end(); first != end; ++first)
+ {
+ switch(*first) {
+ case ' ': ++length; break;
+ // hardcoded tab to 4 for now
+ case '\t': length = ((length + 4) / 4) * 4; break;
+ default: BOOST_ASSERT(false);
+ }
+ }
+
+ return length;
         }
-
- list_indent = -1; // reset
     }
 
- void list_format_action::operator()(iterator first, iterator last) const
+ void list_action(quickbook::actions& actions, value list)
     {
- if(!actions.output_pre(out)) return;
-
- int new_indent = 0;
- while (first != last && (*first == ' ' || *first == '\t'))
- {
- char mark = *first++;
- if (mark == ' ')
- {
- ++new_indent;
- }
- else // must be a tab
- {
- BOOST_ASSERT(mark == '\t');
- // hardcoded tab to 4 for now
- new_indent = ((new_indent + 4) / 4) * 4;
- }
- }
+ if(actions.suppress) return;
 
- char mark = *first;
- BOOST_ASSERT(mark == '#' || mark == '*'); // expecting a mark
+ typedef std::pair<char, int> mark_type;
+ std::stack<mark_type> list_marks;
+ int list_indent = -1;
 
- if (list_indent == -1) // the very start
+ BOOST_FOREACH(value_consumer values, list)
         {
- BOOST_ASSERT(new_indent == 0);
- }
+ int new_indent = indent_length(
+ values.consume(general_tags::list_indent).get_quickbook());
+ value mark_value = values.consume(general_tags::list_mark);
+ std::string content = values.consume().get_boostbook();
+ assert(!values.is());
 
- if (new_indent > list_indent)
- {
- list_indent = new_indent;
- list_marks.push(mark_type(mark, list_indent));
- if (list_marks.size() > 1)
+ char mark = mark_value.get_quickbook()[0];
+ assert(mark == '*' || mark == '#');
+
+ if(list_indent == -1) {
+ assert(new_indent == 0);
+ }
+
+ if(new_indent > list_indent)
             {
- // Make this new list a child of the previous list.
- // The previous listelem has already ended so we erase
- // "</listitem>" to accomodate this sub-list. We'll close
- // the listelem later.
+ list_indent = new_indent;
+ list_marks.push(mark_type(mark, list_indent));
 
- std::string str;
- out.swap(str);
- std::string::size_type pos = str.rfind("</listitem>");
- BOOST_ASSERT(pos <= str.size());
- str.erase(str.begin()+pos, str.end());
- out << str;
+ actions.out << ((mark == '#') ? "<orderedlist>\n" : "<itemizedlist>\n");
             }
- out << std::string((mark == '#') ? "<orderedlist>\n" : "<itemizedlist>\n");
- }
+ else if (new_indent < list_indent)
+ {
+ BOOST_ASSERT(!list_marks.empty());
+ list_indent = new_indent;
 
- else if (new_indent < list_indent)
- {
- BOOST_ASSERT(!list_marks.empty());
- list_indent = new_indent;
+ while (!list_marks.empty() && (list_indent < list_marks.top().second))
+ {
+ char mark = list_marks.top().first;
+ list_marks.pop();
+ actions.out << "</listitem>";
+ actions.out << ((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
+ }
 
- while (!list_marks.empty() && (list_indent < list_marks.top().second))
+ actions.out << "</listitem>";
+ }
+ else
             {
- char mark = list_marks.top().first;
- list_marks.pop();
- out << std::string((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
- if (list_marks.size() >= 1)
- out << "</listitem>";
+ actions.out << "</listitem>";
+ }
+
+ if (mark != list_marks.top().first) // new_indent == list_indent
+ {
+ file_position const pos = mark_value.get_position();
+ detail::outerr(actions.filename, pos.line)
+ << "Illegal change of list style near column " << pos.column << ".\n";
+ detail::outwarn(actions.filename, pos.line)
+ << "Ignoring change of list style" << std::endl;
+ ++actions.error_count;
             }
+
+ actions.out << "<listitem>";
+ actions.out << "<simpara>\n";
+ actions.out << content;
+ actions.out << "\n</simpara>";
         }
 
- if (mark != list_marks.top().first) // new_indent == list_indent
+ assert(!list_marks.empty());
+ while (!list_marks.empty())
         {
- file_position const pos = first.get_position();
- detail::outerr(actions.filename, pos.line)
- << "Illegal change of list style near column " << pos.column << ".\n";
- detail::outwarn(actions.filename, pos.line)
- << "Ignoring change of list style" << std::endl;
- ++error_count;
+ char mark = list_marks.top().first;
+ list_marks.pop();
+ actions.out << "</listitem>";
+ actions.out << ((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
         }
     }
 

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -117,35 +117,6 @@
         quickbook::actions& actions;
     };
 
- struct phrase_action
- {
- // blurb, blockquote, preformatted, list_item,
- // unordered_list, ordered_list
-
- phrase_action(
- collector& out,
- collector& phrase,
- std::string const& pre,
- std::string const& post,
- quickbook::actions& actions)
- : out(out)
- , phrase(phrase)
- , pre(pre)
- , post(post)
- , actions(actions) {}
-
- void operator()(iterator first, iterator last) const { return (*this)(); }
- template <typename T>
- void operator()(T const&) const { return (*this)(); }
- void operator()() const;
-
- collector& out;
- collector& phrase;
- std::string pre;
- std::string post;
- quickbook::actions& actions;
- };
-
     struct paragraph_action
     {
         // implicit paragraphs
@@ -198,58 +169,6 @@
         bool saved_suppress;
     };
 
- struct list_action
- {
- // Handles lists
-
- typedef std::pair<char, int> mark_type;
- list_action(
- collector& out
- , collector& list_buffer
- , int& list_indent
- , std::stack<mark_type>& list_marks
- , quickbook::actions& actions)
- : out(out)
- , list_buffer(list_buffer)
- , list_indent(list_indent)
- , list_marks(list_marks)
- , actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- collector& out;
- collector& list_buffer;
- int& list_indent;
- std::stack<mark_type>& list_marks;
- quickbook::actions& actions;
- };
-
- struct list_format_action
- {
- // Handles list formatting and hierarchy
-
- typedef std::pair<char, int> mark_type;
- list_format_action(
- collector& out
- , int& list_indent
- , std::stack<mark_type>& list_marks
- , int& error_count
- , quickbook::actions& actions)
- : out(out)
- , list_indent(list_indent)
- , list_marks(list_marks)
- , error_count(error_count)
- , actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- collector& out;
- int& list_indent;
- std::stack<mark_type>& list_marks;
- int& error_count;
- quickbook::actions& actions;
- };
-
     struct span
     {
         // Decorates c++ code fragments

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -33,7 +33,6 @@
 
     // auxilliary streams
         , phrase()
- , list_buffer()
 
     // value actions
         , values()
@@ -57,8 +56,6 @@
 
     // temporary or global state
         , macro_id()
- , list_marks()
- , list_indent(-1)
         , template_depth(0)
         , templates()
         , error_count(0)
@@ -80,10 +77,6 @@
         , raw_char(phrase, *this)
         , escape_unicode(phrase, *this)
 
- , list(out, list_buffer, list_indent, list_marks, *this)
- , list_format(list_buffer, list_indent, list_marks, error_count, *this)
- , list_item(list_buffer, phrase, list_item_pre, list_item_post, *this)
-
         , simple_bold(phrase, bold_pre_, bold_post_, macro, *this)
         , simple_italic(phrase, italic_pre_, italic_post_, macro, *this)
         , simple_underline(phrase, underline_pre_, underline_post_, macro, *this)
@@ -135,7 +128,6 @@
 
         out.push();
         phrase.push();
- list_buffer.push();
         templates.push();
         values.builder.save();
     }
@@ -176,7 +168,6 @@
 
         out.pop();
         phrase.pop();
- list_buffer.pop();
         templates.pop();
         values.builder.restore();
     }

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -35,7 +35,6 @@
 
         typedef std::vector<std::string> string_list;
 
- typedef std::pair<char, int> mark_type;
         static int const max_template_depth = 100;
 
     // header info
@@ -48,7 +47,6 @@
 
     // auxilliary streams
         collector phrase;
- collector list_buffer;
 
     // value actions
         value_parser values;
@@ -91,8 +89,6 @@
 
     // temporary or global state
         std::string macro_id;
- std::stack<mark_type> list_marks;
- int list_indent;
         int template_depth;
         template_stack templates;
         int error_count;
@@ -124,10 +120,6 @@
         raw_char_action raw_char;
         escape_unicode_action escape_unicode;
 
- list_action list;
- list_format_action list_format;
- phrase_action list_item;
-
         simple_phrase_action simple_bold;
         simple_phrase_action simple_italic;
         simple_phrase_action simple_underline;

Modified: branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -23,6 +23,7 @@
         (variable_list)(table)
         (xinclude)(import)(include)
         (paragraph)
+ (list)
     )
 
     QUICKBOOK_VALUE_TAGS(table_tags, 0x250,
@@ -30,7 +31,7 @@
     )
 
     QUICKBOOK_VALUE_TAGS(general_tags, 0x300,
- (element_id)(include_id)
+ (element_id)(include_id)(list_indent)(list_mark)
     )
 
 }

Modified: branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -154,7 +154,7 @@
 
         local.blocks =
            *( local.code
- | local.list [actions.list]
+ | local.list
             | local.hr [actions.hr]
             | +eol
             )
@@ -205,23 +205,30 @@
             ;
 
         local.list =
- cl::eps_p(cl::ch_p('*') | '#') >>
- +(
- (*cl::blank_p
- >> (cl::ch_p('*') | '#')) [actions.list_format]
- >> *cl::blank_p
- >> local.list_item
- ) [actions.list_item]
+ cl::eps_p(cl::ch_p('*') | '#')
+ [actions.values.reset()]
+ >> actions.values.list(block_tags::list)
+ [ +actions.values.list()
+ [ (*cl::blank_p) [actions.values.entry(ph::arg1, ph::arg2, general_tags::list_indent)]
+ >> (cl::ch_p('*') | '#')
+ [actions.values.entry(ph::arg1, ph::arg2, general_tags::list_mark)]
+ >> *cl::blank_p
+ >> local.list_item [actions.phrase_value]
+ ]
+ ] [actions.element]
             ;
 
         local.list_item =
- *( common
- | (cl::anychar_p -
- ( cl::eol_p >> *cl::blank_p
- >> (cl::ch_p('*') | '#' | cl::eol_p)
- )
- ) [actions.plain_char]
- )
+ actions.values.save()
+ [
+ *( common
+ | (cl::anychar_p -
+ ( cl::eol_p >> *cl::blank_p
+ >> (cl::ch_p('*') | '#' | cl::eol_p)
+ )
+ ) [actions.plain_char]
+ )
+ ]
>> +eol
             ;
 
@@ -473,9 +480,11 @@
 
 
         local.command_line_phrase =
- *( common
- | (cl::anychar_p - ']') [actions.plain_char]
- )
+ actions.values.save()
+ [ *( common
+ | (cl::anychar_p - ']') [actions.plain_char]
+ )
+ ]
             ;
 
         // Miscellaneous stuff

Modified: branches/quickbook-filenames/tools/quickbook/test/list_test.gold
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/list_test.gold (original)
+++ branches/quickbook-filenames/tools/quickbook/test/list_test.gold 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -210,6 +210,35 @@
       </simpara>
     </listitem>
   </orderedlist>
+ <para>
+ Markup in list:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ <emphasis role="bold">Bold</emphasis>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <emphasis role="bold">Bold</emphasis>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <quote>Quoted</quote>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <footnote>
+ <para>
+ Footnote
+ </para>
+ </footnote>
+ </simpara>
+ </listitem>
+ </itemizedlist>
   <section id="list_test.list_immediately_following_markup">
     <title><link linkend="list_test.list_immediately_following_markup">List immediately
     following markup</link></title>

Modified: branches/quickbook-filenames/tools/quickbook/test/list_test.quickbook
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/list_test.quickbook (original)
+++ branches/quickbook-filenames/tools/quickbook/test/list_test.quickbook 2011-02-22 15:41:36 EST (Tue, 22 Feb 2011)
@@ -52,6 +52,13 @@
 # G
 # H
 
+Markup in list:
+
+* *Bold*
+* [*Bold]
+* ["Quoted]
+* [footnote Footnote]
+
 [section List immediately following markup]
 * One
 * Two


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