Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59304 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2010-01-27 17:02:47


Author: danieljames
Date: 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
New Revision: 59304
URL: http://svn.boost.org/trac/boost/changeset/59304

Log:
Headings, variable lists, tables.
Added:
   branches/quickbook-1.5-spirit2/block.hpp (contents, props changed)
   branches/quickbook-1.5-spirit2/block_actions.cpp (contents, props changed)
   branches/quickbook-1.5-spirit2/block_list.cpp (contents, props changed)
   branches/quickbook-1.5-spirit2/parse_types.hpp (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/block.cpp | 253 +++++++++++++++++++++------------------
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 128 --------------------
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 130 --------------------
   branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 34 -----
   branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 24 ---
   branches/quickbook-1.5-spirit2/phrase.cpp | 6
   branches/quickbook-1.5-spirit2/phrase.hpp | 25 ---
   7 files changed, 141 insertions(+), 459 deletions(-)

Modified: branches/quickbook-1.5-spirit2/block.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.cpp (original)
+++ branches/quickbook-1.5-spirit2/block.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -14,10 +14,13 @@
 #include "./detail/utils.hpp"
 #include "./detail/actions_class.hpp"
 #include "./parse_utils.hpp"
+#include "./detail/markups.hpp"
 #include <boost/spirit/include/qi_core.hpp>
 #include <boost/spirit/include/qi_eol.hpp>
 #include <boost/spirit/include/qi_eps.hpp>
 #include <boost/spirit/include/qi_attr.hpp>
+#include <boost/spirit/include/qi_attr_cast.hpp>
+#include <boost/spirit/include/qi_repeat.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_container.hpp>
@@ -57,6 +60,25 @@
     (char const*, dummy)
 )
 
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::heading,
+ (int, level)
+ (quickbook::title, content)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::variablelist,
+ (std::string, title)
+ (std::vector<quickbook::varlistentry>, entries)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::table,
+ (boost::optional<std::string>, id)
+ (std::string, title)
+ (std::vector<quickbook::table_row>, rows)
+)
+
 namespace quickbook
 {
     namespace qi = boost::spirit::qi;
@@ -71,16 +93,12 @@
         phrase_grammar common;
         qi::rule<iterator>
                         start_, blocks, block_markup, code, code_line,
- space, blank, comment, headings, h, h1, h2,
- h3, h4, h5, h6, blurb, blockquote, admonition,
+ space, blank, comment,
                         phrase, phrase_end, ordered_list, def_macro,
- macro_identifier, table, table_row, variablelist,
- varlistentry, varlistterm, varlistitem, table_cell,
- preformatted,
+ macro_identifier,
                         xinclude, include, hard_space, eol, paragraph_end,
                         template_, template_id, template_formal_arg,
- template_body, identifier, dummy_block, import,
- inside_paragraph;
+ template_body, identifier, dummy_block, import;
 
         qi::symbols<> paragraph_end_markups;
         qi::rule<iterator, quickbook::paragraph()> paragraph;
@@ -97,11 +115,32 @@
 
         qi::rule<iterator, quickbook::begin_section()> begin_section;
         qi::rule<iterator, quickbook::end_section()> end_section;
+
+ qi::symbols<char, int> heading_symbol;
+ qi::rule<iterator, quickbook::heading()> heading;
+
+ qi::rule<iterator, std::string()> inside_paragraph;
+ qi::rule<iterator, quickbook::formatted()> inside_paragraph2;
+
+ qi::symbols<char, quickbook::markup> paragraph_blocks;
+ qi::rule<iterator, quickbook::formatted()> paragraph_block, blockquote, preformatted;
+
+ qi::rule<iterator, quickbook::variablelist()> variablelist;
+ qi::rule<iterator, quickbook::varlistentry()> varlistentry;
+ qi::rule<iterator, quickbook::formatted()>
+ varlistterm, varlistterm_body,
+ varlistitem, varlistitem_body;
+
+ qi::rule<iterator, quickbook::table()> table;
+ qi::rule<iterator, quickbook::table_row()> table_row;
+ qi::rule<iterator, quickbook::table_cell()> table_cell;
+ qi::rule<iterator, quickbook::formatted()> table_cell_body;
         
         qi::rule<iterator, quickbook::title()> title_phrase;
         qi::rule<iterator, std::string()> phrase_attr;
         
         qi::rule<iterator, file_position()> position;
+ qi::rule<iterator> error;
     };
 
     block_grammar::block_grammar(quickbook::actions& actions_)
@@ -171,21 +210,20 @@
                 '[' >> space
>> ( begin_section [actions.process][actions.output]
                 | end_section [actions.process][actions.output]
- | headings
- | blurb
- | blockquote
- | admonition
- | preformatted
+ | heading [actions.process][actions.output]
+ | paragraph_block [actions.process][actions.output]
+ | blockquote [actions.process][actions.output]
+ | preformatted [actions.process][actions.output]
                 | def_macro
- | table
- | variablelist
+ | table [actions.process][actions.output]
+ | variablelist [actions.process][actions.output]
                 | xinclude
                 | include
                 | import
                 | template_
                 )
>> ( (space >> ']' >> +eol)
- | qi::raw[qi::eps] [actions.error]
+ | error
                 )
             ;
         
@@ -219,60 +257,61 @@
>> qi::attr("dummy")
             ;
 
- headings =
- h1 | h2 | h3 | h4 | h5 | h6 | h
- ;
+ heading = heading_symbol >> hard_space >> title_phrase;
 
- h = "heading" >> hard_space >> qi::raw[phrase] [actions.h];
- h1 = "h1" >> hard_space >> qi::raw[phrase] [actions.h1];
- h2 = "h2" >> hard_space >> qi::raw[phrase] [actions.h2];
- h3 = "h3" >> hard_space >> qi::raw[phrase] [actions.h3];
- h4 = "h4" >> hard_space >> qi::raw[phrase] [actions.h4];
- h5 = "h5" >> hard_space >> qi::raw[phrase] [actions.h5];
- h6 = "h6" >> hard_space >> qi::raw[phrase] [actions.h6];
+ heading_symbol.add
+ ("h1", 1)
+ ("h2", 2)
+ ("h3", 3)
+ ("h4", 4)
+ ("h5", 5)
+ ("h6", 6)
+ ("heading", -1);
 
         static const bool true_ = true;
         static const bool false_ = false;
 
         inside_paragraph =
- phrase [actions.inside_paragraph]
- >> *(
- eol >> eol >> phrase [actions.inside_paragraph]
- )
+ qi::eps [actions.phrase_push]
+ >> inside_paragraph2 [actions.process]
+ >> *( eol
+ >> eol
+ >> inside_paragraph2 [actions.process]
+ )
+ >> qi::eps [actions.phrase_pop]
             ;
 
- blurb =
- "blurb" >> hard_space
- >> inside_paragraph [actions.blurb]
- >> qi::eps
+ inside_paragraph2 =
+ qi::attr(markup(paragraph_pre, paragraph_post))
+ >> phrase_attr;
+
+ paragraph_blocks.add
+ ("blurb", markup(blurb_pre, blurb_post))
+ ("warning", markup(warning_pre, warning_post))
+ ("caution", markup(caution_pre, caution_post))
+ ("important", markup(important_pre, important_post))
+ ("note", markup(note_pre, note_post))
+ ("tip", markup(tip_pre, tip_post))
+ ;
+
+ paragraph_block =
+ paragraph_blocks >> hard_space >> inside_paragraph
             ;
 
         blockquote =
- ':' >> blank >>
- inside_paragraph [actions.blockquote]
+ ':'
+ >> blank
+ >> qi::attr(markup(blockquote_pre, blockquote_post))
+ >> inside_paragraph
             ;
 
- admonition =
- "warning" >> blank >>
- inside_paragraph [actions.warning]
- |
- "caution" >> blank >>
- inside_paragraph [actions.caution]
- |
- "important" >> blank >>
- inside_paragraph [actions.important]
- |
- "note" >> blank >>
- inside_paragraph [actions.note]
- |
- "tip" >> blank >>
- inside_paragraph [actions.tip]
- ;
-
- preformatted =
- "pre" >> hard_space [ph::ref(no_eols) = false_]
- >> -eol >> phrase [actions.preformatted]
- >> qi::eps [ph::ref(no_eols) = true_]
+ preformatted %=
+ "pre"
+ >> hard_space [ph::ref(no_eols) = false_]
+ >> -eol
+ >> qi::attr(markup(preformatted_pre, preformatted_post))
+ >> phrase_attr
+ >> qi::eps [ph::ref(no_eols) = true_]
             ;
 
         macro_identifier =
@@ -314,95 +353,80 @@
>> space >> &qi::lit(']')
             ;
 
- variablelist = (
- "variablelist"
- >> qi::omit[&(*qi::blank >> qi::eol) | hard_space]
+ variablelist =
+ "variablelist"
+ >> (&(*qi::blank >> qi::eol) | hard_space)
>> *(qi::char_ - eol)
>> +eol
>> *varlistentry
- ) [ph::bind(actions.variablelist, as_string(qi::_1))]
             ;
 
         varlistentry =
- space
- >> qi::char_('[') [actions.start_varlistentry]
- >>
- (
- (
- varlistterm
- >> +varlistitem
- >> qi::char_(']') [actions.end_varlistentry]
- >> space
+ space
+ >> '['
+ >> ( varlistterm
+ >> +varlistitem
+ >> ']'
+ >> space
+ | error >> qi::attr(quickbook::varlistentry())
                 )
- | qi::raw[qi::eps] [actions.error]
- )
             ;
 
         varlistterm =
- space
- >> qi::char_('[') [actions.start_varlistterm]
- >>
- (
- (
- phrase
- >> qi::char_(']') [actions.end_varlistterm]
- >> space
+ space
+ >> '['
+ >> ( varlistterm_body >> ']' >> space
+ | error >> qi::attr(quickbook::formatted())
                 )
- | qi::raw[qi::eps] [actions.error]
- )
+ ;
+
+ varlistterm_body =
+ qi::attr(markup(start_varlistterm_, end_varlistterm_))
+ >> phrase_attr
             ;
 
         varlistitem =
- space
- >> qi::char_('[') [actions.start_varlistitem]
- >>
- (
- (
- inside_paragraph
- >> qi::char_(']') [actions.end_varlistitem]
- >> space
+ space
+ >> '['
+ >> ( varlistitem_body >> ']' >> space
+ | error >> qi::attr(quickbook::formatted())
                 )
- | qi::raw[qi::eps] [actions.error]
- )
             ;
 
- table = (
- "table"
+ varlistitem_body =
+ qi::attr(markup(start_varlistitem_, end_varlistitem_))
+ >> inside_paragraph
+ ;
+
+ table =
+ "table"
>> (&(*qi::blank >> qi::eol) | hard_space)
>> element_id_1_5
>> (&(*qi::blank >> qi::eol) | space)
>> *(qi::char_ - eol)
>> +eol
>> *table_row
- ) [ph::bind(actions.table, qi::_1, as_string(qi::_2))]
             ;
 
         table_row =
- space
- >> qi::char_('[') [actions.start_row]
- >>
- (
- (
- *table_cell
- >> qi::char_(']') [actions.end_row]
- >> space
+ space
+ >> '['
+ >> ( *table_cell >> ']' >> space
+ | error >> qi::attr(quickbook::table_row())
                 )
- | qi::raw[qi::eps] [actions.error]
- )
             ;
 
         table_cell =
- space
- >> qi::char_('[') [actions.start_cell]
- >>
- (
- (
- inside_paragraph
- >> qi::char_(']') [actions.end_cell]
- >> space
+ space
+ >> '['
+ >> ( table_cell_body >> ']' >> space
+ | error >> qi::attr(quickbook::table_cell())
                 )
- | qi::raw[qi::eps] [actions.error]
- )
+ ;
+
+ table_cell_body =
+ qi::attr(markup(start_cell_, end_cell_))
+ >> inside_paragraph
             ;
 
         xinclude =
@@ -520,5 +544,6 @@
             ;
 
         position = qi::raw[qi::eps] [get_position];
+ error = qi::raw[qi::eps] [actions.error];
     }
 }

Added: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/block.hpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -0,0 +1,94 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP
+
+#include <string>
+#include <vector>
+#include <boost/optional.hpp>
+#include <boost/spirit/include/classic_position_iterator.hpp>
+#include "./parse_types.hpp"
+
+namespace quickbook
+{
+ class actions;
+ typedef boost::spirit::classic::file_position file_position;
+
+ struct hr
+ {
+ };
+
+ struct paragraph
+ {
+ std::string content;
+ char const* dummy;
+ };
+
+ struct list_item
+ {
+ file_position position;
+ std::string indent;
+ char mark;
+ std::string content;
+ };
+
+ struct title
+ {
+ std::string raw_markup;
+ std::string content;
+ };
+
+ struct begin_section
+ {
+ boost::optional<std::string> id;
+ title content;
+ };
+
+ struct end_section
+ {
+ quickbook::file_position position;
+ char const* dummy;
+ };
+
+ struct heading
+ {
+ int level;
+ title content;
+ };
+
+ typedef std::vector<quickbook::formatted> varlistentry;
+
+ struct variablelist
+ {
+ std::string title;
+ std::vector<varlistentry> entries;
+ };
+
+ typedef quickbook::formatted table_cell;
+ typedef std::vector<table_cell> table_row;
+
+ struct table
+ {
+ boost::optional<std::string> id;
+ std::string title;
+ std::vector<table_row> rows;
+ };
+
+ void process(quickbook::actions&, hr);
+ void process(quickbook::actions&, paragraph const&);
+ void process(quickbook::actions&, std::vector<list_item> const&);
+ void process(quickbook::actions&, begin_section const&);
+ void process(quickbook::actions&, end_section const&);
+ void process(quickbook::actions&, heading const&);
+ void process(quickbook::actions&, variablelist const&);
+ void process(quickbook::actions&, table const&);
+}
+
+#endif
\ No newline at end of file

Added: branches/quickbook-1.5-spirit2/block_actions.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/block_actions.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -0,0 +1,266 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include "./block.hpp"
+#include "./detail/actions_class.hpp"
+#include "./detail/markups.hpp"
+#include "./detail/quickbook.hpp"
+#include <boost/assert.hpp>
+
+namespace quickbook
+{
+ namespace {
+ std::string fully_qualified_id(std::string const& library_id,
+ std::string const& qualified_section_id,
+ std::string const& section_id)
+ {
+ std::string id = library_id;
+ if(!id.empty() && !qualified_section_id.empty()) id += '.';
+ id += qualified_section_id;
+ if(!id.empty() && !section_id.empty()) id += '.';
+ id += section_id;
+ return id;
+ }
+ }
+
+ void process(quickbook::actions& actions, hr)
+ {
+ actions.phrase << hr_;
+ }
+
+ void process(quickbook::actions& actions, paragraph const& x)
+ {
+ actions.phrase << paragraph_pre << x.content << paragraph_post;
+ }
+
+ void process(quickbook::actions& actions, begin_section const& x)
+ {
+ // TODO: This uses the generated title.
+ actions.section_id = x.id ? *x.id :
+ detail::make_identifier(
+ x.content.raw_markup.begin(),
+ x.content.raw_markup.end());
+
+ if (actions.section_level != 0) {
+ actions.qualified_section_id += '.';
+ }
+ else {
+ BOOST_ASSERT(actions.qualified_section_id.empty());
+ }
+
+ actions.qualified_section_id += actions.section_id;
+ ++actions.section_level;
+
+ if (qbk_version_n < 103) // version 1.2 and below
+ {
+ actions.phrase << "\n<section id=\""
+ << actions.doc_id << "."
+ << actions.section_id << "\">\n";
+ }
+ else // version 1.3 and above
+ {
+ actions.phrase << "\n<section id=\""
+ << actions.doc_id
+ << "."
+ << actions.qualified_section_id << "\">\n";
+ }
+
+ if (qbk_version_n < 103) // version 1.2 and below
+ {
+ actions.phrase << "<title>" << x.content.content << "</title>\n";
+ }
+ else // version 1.3 and above
+ {
+ actions.phrase
+ << "<title>"
+ << "<link linkend=\""
+ << actions.doc_id
+ << "."
+ << actions.qualified_section_id << "\">"
+ << x.content.content
+ << "</link>"
+ << "</title>\n"
+ ;
+ }
+
+ }
+
+ void process(quickbook::actions& actions, end_section const& x)
+ {
+ actions.phrase << "</section>";
+
+ --actions.section_level;
+ if (actions.section_level < 0)
+ {
+ detail::outerr(x.position.file,x.position.line)
+ << "Mismatched [endsect] near column " << x.position.column << ".\n";
+ ++actions.error_count;
+
+ // $$$ TODO: somehow fail parse else BOOST_ASSERT(std::string::npos != n)
+ // $$$ below will assert.
+ }
+ if (actions.section_level == 0)
+ {
+ actions.qualified_section_id.clear();
+ }
+ else
+ {
+ std::string::size_type const n =
+ actions.qualified_section_id.find_last_of('.');
+ BOOST_ASSERT(std::string::npos != n);
+ actions.qualified_section_id.erase(n, std::string::npos);
+ }
+ }
+
+ void process(quickbook::actions& actions, heading const& x)
+ {
+ // TODO: Is this right?
+ bool new_style = qbk_version_n >= 103 || x.level > 0;
+
+ int level = x.level;
+ if(level < 0) {
+ level = actions.section_level + 2; // section_level is zero-based. We need to use a
+ // one-based heading which is one greater
+ // than the current. Thus: section_level + 2.
+ if (level > 6) // The max is h6, clip it if it goes
+ level = 6; // further than that
+ }
+
+ if (!new_style) // version 1.2 and below
+ {
+ actions.phrase
+ << "<anchor id=\""
+ << actions.section_id << '.'
+ << detail::make_identifier(
+ x.content.raw_markup.begin(),
+ x.content.raw_markup.end())
+ << "\" />"
+ << "<bridgehead renderas=\"sect" << level << "\">"
+ << x.content.content
+ << "</bridgehead>"
+ ;
+ }
+ else // version 1.3 and above
+ {
+ std::string anchor = fully_qualified_id(
+ actions.doc_id, actions.qualified_section_id,
+ detail::make_identifier(
+ x.content.raw_markup.begin(),
+ x.content.raw_markup.end()));
+
+ actions.phrase
+ << "<anchor id=\"" << anchor << "\"/>"
+ << "<bridgehead renderas=\"sect" << level << "\">"
+ << "<link linkend=\"" << anchor << "\">"
+ << x.content.content
+ << "</link>"
+ << "</bridgehead>"
+ ;
+ }
+ }
+
+ void process(quickbook::actions& actions, variablelist const& x)
+ {
+ actions.phrase << "<variablelist>\n";
+
+ actions.phrase << "<title>";
+ detail::print_string(x.title, actions.phrase.get());
+ actions.phrase << "</title>\n";
+
+ for(std::vector<varlistentry>::const_iterator
+ it = x.entries.begin(); it != x.entries.end(); ++it)
+ {
+ actions.phrase << start_varlistentry_;
+ std::for_each(it->begin(), it->end(), actions.process);
+ actions.phrase << end_varlistentry_;
+ }
+
+ actions.phrase << "</variablelist>\n";
+ }
+
+
+ void process(quickbook::actions& actions, table const& x)
+ {
+ bool has_title = !x.title.empty();
+
+ std::string table_id;
+ if(qbk_version_n >= 105) {
+ if(x.id) {
+ table_id = fully_qualified_id(actions.doc_id,
+ actions.qualified_section_id, *x.id);
+ }
+ else if(has_title) {
+ table_id = fully_qualified_id(actions.doc_id,
+ actions.qualified_section_id,
+ detail::make_identifier(x.title.begin(), x.title.end()));
+ }
+ }
+
+ if (has_title)
+ {
+ actions.phrase << "<table frame=\"all\"";
+ if(!table_id.empty())
+ actions.phrase << " id=\"" << table_id << "\"";
+ actions.phrase << ">\n";
+ actions.phrase << "<title>";
+ detail::print_string(x.title, actions.phrase.get());
+ actions.phrase << "</title>";
+ }
+ else
+ {
+ actions.phrase << "<informaltable frame=\"all\"";
+ if(!table_id.empty())
+ actions.phrase << " id=\"" << table_id << "\"";
+ actions.phrase << ">\n";
+ }
+
+ // This is a bit odd for backwards compatability: the old version just
+ // used the last count that was calculated.
+ actions.phrase << "<tgroup cols=\""
+ << (x.rows.empty() ? 0 : x.rows.back().size())
+ << "\">\n";
+
+ std::vector<table_row>::const_iterator row = x.rows.begin();
+
+ // Backwards compatability again: the old version turned the first row
+ // into a header at the start of the second row. So it only happened
+ // when there was more than one row.
+ if (x.rows.size() > 1)
+ {
+ actions.phrase << "<thead>";
+ actions.phrase << start_row_;
+ std::for_each(row->begin(), row->end(), actions.process);
+ actions.phrase << end_row_;
+ actions.phrase << "</thead>\n";
+ ++row;
+ }
+
+ actions.phrase << "<tbody>\n";
+
+ while(row != x.rows.end()) {
+ actions.phrase << start_row_;
+ std::for_each(row->begin(), row->end(), actions.process);
+ actions.phrase << end_row_;
+ ++row;
+ }
+
+ actions.phrase << "</tbody>\n"
+ << "</tgroup>\n";
+
+ if (has_title)
+ {
+ actions.phrase << "</table>\n";
+ }
+ else
+ {
+ actions.phrase << "</informaltable>\n";
+ }
+ }
+}
\ No newline at end of file

Added: branches/quickbook-1.5-spirit2/block_list.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/block_list.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -0,0 +1,98 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include "./block.hpp"
+#include "./detail/actions_class.hpp"
+#include <boost/assert.hpp>
+
+namespace quickbook
+{
+ typedef std::pair<char, int> mark_type;
+
+ namespace {
+ int indent_length(std::string const& indent)
+ {
+ 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;
+ }
+ }
+
+ void process(quickbook::actions& actions, std::vector<list_item> const& list)
+ {
+ int list_indent = -1;
+ std::stack<mark_type> list_marks;
+
+ for(std::vector<list_item>::const_iterator
+ it = list.begin(), end = list.end(); it != end; ++it)
+ {
+ int new_indent = indent_length(it->indent);
+ BOOST_ASSERT(it->mark == '#' || it->mark == '*');
+
+ // The first item shouldn't be indented.
+ BOOST_ASSERT(list_indent != -1 || new_indent == 0);
+
+ if (new_indent > list_indent)
+ {
+ list_indent = new_indent;
+ list_marks.push(mark_type(it->mark, list_indent));
+ actions.phrase << std::string(it->mark == '#' ? "<orderedlist>\n" : "<itemizedlist>\n");
+ }
+ else if(new_indent == list_indent)
+ {
+ actions.phrase << std::string("\n</listitem>");
+ }
+ else if (new_indent < list_indent)
+ {
+ list_indent = new_indent;
+
+ // TODO: This assumes that list_indent is equal to one of the
+ // existing indents.
+ while (!list_marks.empty() && (list_indent < list_marks.top().second))
+ {
+ actions.phrase << std::string("\n</listitem>");
+ actions.phrase << std::string(list_marks.top().first == '#' ? "\n</orderedlist>" : "\n</itemizedlist>");
+ list_marks.pop();
+ }
+ BOOST_ASSERT(!list_marks.empty());
+ actions.phrase << std::string("\n</listitem>");
+ }
+
+ if (it->mark != list_marks.top().first)
+ {
+ boost::spirit::classic::file_position const pos = it->position;
+ detail::outerr(pos.file,pos.line)
+ << "Illegal change of list style near column " << pos.column << ".\n";
+ detail::outwarn(pos.file,pos.line)
+ << "Ignoring change of list style" << std::endl;
+ ++actions.error_count;
+ }
+
+ actions.phrase << "<listitem>\n" << it->content;
+ }
+
+ while (!list_marks.empty())
+ {
+ actions.phrase << std::string("\n</listitem>");
+ actions.phrase << std::string(list_marks.top().first == '#' ? "\n</orderedlist>" : "\n</itemizedlist>");
+ list_marks.pop();
+ }
+ }
+}
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -249,134 +249,6 @@
         actions.template_info.clear();
     }
 
- void variablelist_action::operator()(std::string const& title) const
- {
- actions.out << "<variablelist>\n";
-
- actions.out << "<title>";
- std::string::const_iterator first = title.begin();
- std::string::const_iterator last = title.end();
- while (first != last)
- detail::print_char(*first++, actions.out.get());
- actions.out << "</title>\n";
-
- std::string str;
- actions.phrase.swap(str);
- actions.out << str;
-
- actions.out << "</variablelist>\n";
- actions.table_span = 0;
- actions.table_header.clear();
- }
-
- void start_varlistitem_action::operator()(unused_type, unused_type, unused_type) const
- {
- phrase << start_varlistitem_;
- phrase.push();
- }
-
- void end_varlistitem_action::operator()(unused_type, unused_type, unused_type) const
- {
- std::string str;
- temp_para.swap(str);
- phrase.pop();
- phrase << str << end_varlistitem_;
- }
-
- void table_action::operator()(boost::optional<std::string> const& id, std::string const& title) const
- {
- std::string::const_iterator first = title.begin();
- std::string::const_iterator last = title.end();
- bool has_title = first != last;
-
- std::string table_id;
- if(qbk_version_n >= 105) {
- if(id) {
- table_id = fully_qualified_id(actions.doc_id,
- actions.qualified_section_id, *id);
- }
- else if(has_title) {
- table_id = fully_qualified_id(actions.doc_id,
- actions.qualified_section_id,
- detail::make_identifier(first, last));
- }
- }
-
- if (has_title)
- {
- actions.out << "<table frame=\"all\"";
- if(!table_id.empty())
- actions.out << " id=\"" << table_id << "\"";
- actions.out << ">\n";
- actions.out << "<title>";
- while (first != last)
- detail::print_char(*first++, actions.out.get());
- actions.out << "</title>";
- }
- else
- {
- actions.out << "<informaltable frame=\"all\"";
- if(!table_id.empty())
- actions.out << " id=\"" << table_id << "\"";
- actions.out << ">\n";
- }
-
- actions.out << "<tgroup cols=\"" << actions.table_span << "\">\n";
-
- if (!actions.table_header.empty())
- {
- actions.out << "<thead>" << actions.table_header << "</thead>\n";
- }
-
- actions.out << "<tbody>\n";
-
- std::string str;
- actions.phrase.swap(str);
- actions.out << str;
-
- actions.out << "</tbody>\n"
- << "</tgroup>\n";
-
- if (has_title)
- {
- actions.out << "</table>\n";
- }
- else
- {
- actions.out << "</informaltable>\n";
- }
-
- actions.table_span = 0;
- actions.table_header.clear();
- }
-
- void start_row_action::operator()(unused_type, unused_type, unused_type) const
- {
- // the first row is the header
- if (header.empty() && !phrase.str().empty())
- {
- phrase.swap(header);
- }
-
- phrase << start_row_;
- span = 0;
- }
-
- void start_col_action::operator()(unused_type, unused_type, unused_type) const
- {
- phrase << start_cell_;
- phrase.push();
- ++span;
- }
-
- void end_col_action::operator()(unused_type, unused_type, unused_type) const
- {
- std::string str;
- temp_para.swap(str);
- phrase.pop();
- phrase << str << end_cell_;
- }
-
     void element_id_warning_action::operator()(iterator_range x, unused_type, unused_type) const
     {
         boost::spirit::classic::file_position const pos = x.begin().get_position();

Modified: branches/quickbook-1.5-spirit2/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.hpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -257,16 +257,6 @@
         markup_action(collector& phrase, std::string const& str)
         : phrase(phrase), str(str) {}
 
- void operator()() const
- {
- phrase << str;
- }
-
- void operator()(unused_type) const
- {
- phrase << str;
- }
-
         void operator()(unused_type, unused_type, unused_type) const
         {
             phrase << str;
@@ -313,27 +303,6 @@
         syntax_highlight& syntax_p;
     };
 
- struct start_varlistitem_action
- {
- start_varlistitem_action(collector& phrase)
- : phrase(phrase) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& phrase;
- };
-
- struct end_varlistitem_action
- {
- end_varlistitem_action(collector& phrase, collector& temp_para)
- : phrase(phrase), temp_para(temp_para) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& phrase;
- collector& temp_para;
- };
-
     struct macro_identifier_action
     {
         // Handles macro identifiers
@@ -370,105 +339,6 @@
         quickbook::actions& actions;
     };
 
- struct variablelist_action
- {
- // Handles variable lists
-
- variablelist_action(quickbook::actions& actions)
- : actions(actions) {}
-
- template <typename T>
- struct result { typedef void type; };
-
- void operator()(std::string const&) const;
-
- quickbook::actions& actions;
- };
-
- struct table_action
- {
- // Handles tables
-
- table_action(quickbook::actions& actions)
- : actions(actions) {}
-
- template <typename Arg1, typename Arg2>
- struct result { typedef void type; };
-
- void operator()(boost::optional<std::string> const&, std::string const&) const;
-
- quickbook::actions& actions;
- };
-
- struct start_row_action
- {
- // Handles table rows
-
- start_row_action(collector& phrase, unsigned& span, std::string& header)
- : phrase(phrase), span(span), header(header) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& phrase;
- unsigned& span;
- std::string& header;
- };
-
- struct start_col_action
- {
- // Handles table columns
-
- start_col_action(collector& phrase, unsigned& span)
- : phrase(phrase), span(span) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& phrase;
- unsigned& span;
- };
-
- struct end_col_action
- {
- end_col_action(collector& phrase, collector& temp_para)
- : phrase(phrase), temp_para(temp_para) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& phrase;
- collector& temp_para;
- };
-
- struct begin_section_action
- {
- // Handles begin page
-
- begin_section_action(
- collector& out
- , collector& phrase
- , std::string& library_id
- , std::string& section_id
- , int& section_level
- , std::string& qualified_section_id)
- : out(out)
- , phrase(phrase)
- , library_id(library_id)
- , section_id(section_id)
- , section_level(section_level)
- , qualified_section_id(qualified_section_id) {}
-
- template <typename A1, typename A2>
- struct result { typedef void type; };
-
- void operator()(boost::optional<std::string> const&, iterator_range) const;
-
- collector& out;
- collector& phrase;
- std::string& library_id;
- std::string& section_id;
- int& section_level;
- std::string& qualified_section_id;
- };
-
    struct element_id_warning_action
    {
        void operator()(iterator_range, unused_type, unused_type) const;

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -50,8 +50,6 @@
         , source_mode("c++")
 
     // temporary or global state
- , table_span(0)
- , table_header()
         , macro_id()
         , template_info()
         , template_depth(0)
@@ -70,34 +68,9 @@
         , syntax_p(source_mode, *this)
         , code(out, phrase, syntax_p)
         , paragraph(out, phrase, paragraph_pre, paragraph_post)
- , inside_paragraph(temp_para, phrase, paragraph_pre, paragraph_post)
- , h(out, phrase, doc_id, section_id, qualified_section_id, section_level)
- , h1(out, phrase, doc_id, section_id, qualified_section_id, h1_pre, h1_post)
- , h2(out, phrase, doc_id, section_id, qualified_section_id, h2_pre, h2_post)
- , h3(out, phrase, doc_id, section_id, qualified_section_id, h3_pre, h3_post)
- , h4(out, phrase, doc_id, section_id, qualified_section_id, h4_pre, h4_post)
- , h5(out, phrase, doc_id, section_id, qualified_section_id, h5_pre, h5_post)
- , h6(out, phrase, doc_id, section_id, qualified_section_id, h6_pre, h6_post)
- , hr(out, hr_)
- , blurb(out, temp_para, blurb_pre, blurb_post)
- , blockquote(out, temp_para, blockquote_pre, blockquote_post)
- , preformatted(out, phrase, preformatted_pre, preformatted_post)
- , warning(out, temp_para, warning_pre, warning_post)
- , caution(out, temp_para, caution_pre, caution_post)
- , important(out, temp_para, important_pre, important_post)
- , note(out, temp_para, note_pre, note_post)
- , tip(out, temp_para, tip_pre, tip_post)
         , plain_char(phrase)
         , raw_char(phrase)
 
- , variablelist(*this)
- , start_varlistentry(phrase, start_varlistentry_)
- , end_varlistentry(phrase, end_varlistentry_)
- , start_varlistterm(phrase, start_varlistterm_)
- , end_varlistterm(phrase, end_varlistterm_)
- , start_varlistitem(phrase)
- , end_varlistitem(phrase, temp_para)
-
         , macro_identifier(*this)
         , macro_definition(*this)
         , template_body(*this)
@@ -105,11 +78,6 @@
         , url_post(url_post_)
         , link_pre(link_pre_)
         , link_post(link_post_)
- , table(*this)
- , start_row(phrase, table_span, table_header)
- , end_row(phrase, end_row_)
- , start_cell(phrase, table_span)
- , end_cell(phrase, temp_para)
 
         , xinclude(out, *this)
         , include(*this)
@@ -144,7 +112,6 @@
 
         out.push();
         phrase.push();
- temp_para.push();
         templates.push();
     }
 
@@ -163,7 +130,6 @@
 
         out.pop();
         phrase.pop();
- temp_para.pop();
         templates.pop();
     }
 }

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.hpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -53,7 +53,6 @@
 
     // auxilliary streams
         collector phrase;
- collector temp_para;
 
     // state
         fs::path filename;
@@ -77,11 +76,7 @@
         std::stack<state_tuple> state_stack;
 
     // temporary or global state
- unsigned table_span;
- std::string table_header;
         std::string macro_id;
- std::stack<mark_type> list_marks;
- int list_indent;
         string_list template_info;
         int template_depth;
         template_stack templates;
@@ -105,23 +100,9 @@
         syntax_highlight syntax_p;
         code_action code;
         phrase_action paragraph;
- phrase_action inside_paragraph;
- generic_header_action h;
- header_action h1, h2, h3, h4, h5, h6;
- markup_action hr;
- phrase_action blurb, blockquote, preformatted;
- phrase_action warning, caution, important, note, tip;
         plain_char_action plain_char;
         raw_char_action raw_char;
 
- variablelist_action variablelist;
- markup_action start_varlistentry;
- markup_action end_varlistentry;
- markup_action start_varlistterm;
- markup_action end_varlistterm;
- start_varlistitem_action start_varlistitem;
- end_varlistitem_action end_varlistitem;
-
         macro_identifier_action macro_identifier;
         macro_definition_action macro_definition;
         template_body_action template_body;
@@ -129,11 +110,6 @@
         char const* url_post;
         char const* link_pre;
         char const* link_post;
- table_action table;
- start_row_action start_row;
- markup_action end_row;
- start_col_action start_cell;
- end_col_action end_cell;
 
         element_id_warning_action element_id_warning;
         xinclude_action xinclude;

Added: branches/quickbook-1.5-spirit2/parse_types.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/parse_types.hpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -0,0 +1,48 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_QUICKBOOK_PARSE_TYPES_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_PARSE_TYPES_HPP
+
+#include <string>
+#include <boost/spirit/include/classic_position_iterator.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+
+namespace quickbook
+{
+ // TODO: Add to a forward header somewhere.
+ class actions;
+ struct macro;
+ typedef boost::spirit::classic::file_position file_position;
+
+ struct markup {
+ markup()
+ : pre(""), post("") {}
+ markup(char const* pre, char const* post)
+ : pre(pre), post(post) {}
+
+ char const* pre;
+ char const* post;
+ };
+
+ struct formatted {
+ markup type;
+ std::string content;
+ };
+
+ void process(quickbook::actions&, formatted const&);
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::formatted,
+ (quickbook::markup, type)
+ (std::string, content)
+)
+
+#endif
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/phrase.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.cpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -43,12 +43,6 @@
 )
 
 BOOST_FUSION_ADAPT_STRUCT(
- quickbook::formatted,
- (quickbook::markup, type)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
     quickbook::simple_markup,
     (char, symbol)
     (std::string, raw_content)

Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2010-01-27 17:02:45 EST (Wed, 27 Jan 2010)
@@ -12,32 +12,17 @@
 
 #include <string>
 #include <map>
-#include <boost/spirit/include/classic_position_iterator.hpp>
-#include "detail/template_stack.hpp"
+#include "./parse_types.hpp"
+#include "./detail/template_stack.hpp"
 
 namespace quickbook
 {
- // TODO: Add to a forward header somewhere.
- class actions;
- struct macro;
- typedef boost::spirit::classic::file_position file_position;
-
     struct source_mode {
         source_mode() {}
         source_mode(std::string const& m) : mode(m) {}
 
         std::string mode;
     };
-
- struct markup {
- markup()
- : pre(""), post("") {}
- markup(char const* pre, char const* post)
- : pre(pre), post(post) {}
-
- char const* pre;
- char const* post;
- };
     
     struct template_ {
         file_position position;
@@ -57,11 +42,6 @@
         std::string content;
     };
     
- struct formatted {
- markup type;
- std::string content;
- };
-
     struct simple_markup {
         char symbol;
         std::string raw_content;
@@ -96,7 +76,6 @@
     void process(quickbook::actions&, template_ const&);
     void process(quickbook::actions&, anchor const&);
     void process(quickbook::actions&, link const&);
- void process(quickbook::actions&, formatted const&);
     void process(quickbook::actions&, simple_markup const&);
     void process(quickbook::actions&, code const&);
     void process(quickbook::actions&, cond_phrase const&);


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