Boost logo

Boost-Commit :

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


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

Log:
List.
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 1
   branches/quickbook-1.5-spirit2/block.cpp | 52 +++++++++++++-------
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 100 +++------------------------------------
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 56 ++++------------------
   branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 10 ---
   branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 6 --
   branches/quickbook-1.5-spirit2/parse_utils.hpp | 10 ++++
   branches/quickbook-1.5-spirit2/phrase.cpp | 8 ---
   8 files changed, 65 insertions(+), 178 deletions(-)

Modified: branches/quickbook-1.5-spirit2/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/Jamfile.v2 2010-01-27 17:02:20 EST (Wed, 27 Jan 2010)
@@ -32,6 +32,7 @@
     phrase_image.cpp
     phrase_template.cpp
     block.cpp
+ block_list.cpp
     doc_info.cpp
     detail/syntax_highlight.cpp
     /boost//program_options

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:20 EST (Wed, 27 Jan 2010)
@@ -7,10 +7,9 @@
     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 "./grammars.hpp"
+#include "./block.hpp"
 #include "./detail/quickbook.hpp"
 #include "./detail/utils.hpp"
 #include "./detail/actions_class.hpp"
@@ -22,6 +21,15 @@
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_container.hpp>
 #include <boost/spirit/include/phoenix_bind.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::list_item,
+ (quickbook::file_position, position)
+ (std::string, indent)
+ (char, mark)
+ (std::string, content)
+)
 
 namespace quickbook
 {
@@ -40,15 +48,21 @@
                         start_, blocks, block_markup, code, code_line,
                         paragraph, space, blank, comment, headings, h, h1, h2,
                         h3, h4, h5, h6, hr, blurb, blockquote, admonition,
- phrase, list, phrase_end, ordered_list, def_macro,
+ phrase, phrase_end, ordered_list, def_macro,
                         macro_identifier, table, table_row, variablelist,
                         varlistentry, varlistterm, varlistitem, table_cell,
- preformatted, list_item, begin_section, end_section,
+ preformatted, begin_section, end_section,
                         xinclude, include, hard_space, eol, paragraph_end,
                         template_, template_id, template_formal_arg,
                         template_body, identifier, dummy_block, import,
                         inside_paragraph;
+
+ qi::rule<iterator, std::vector<quickbook::list_item>()> list;
+ qi::rule<iterator, quickbook::list_item()> list_item;
+ qi::rule<iterator, std::string()> list_item_content;
+
         qi::rule<iterator, boost::optional<std::string>()> element_id, element_id_1_5;
+ qi::rule<iterator, file_position()> position;
     };
 
     block_grammar::block_grammar(quickbook::actions& actions_)
@@ -68,7 +82,7 @@
         blocks =
            +( block_markup
             | code
- | list [actions.list]
+ | list [actions.process][actions.output]
             | hr [actions.hr]
             | comment >> *eol
             | paragraph [actions.paragraph]
@@ -387,17 +401,20 @@
             ;
 
         list =
- &(qi::char_('*') | '#') >>
- +qi::raw[
- qi::raw[*qi::blank
- >> (qi::char_('*') | '#')]
- [actions.list_format]
- >> *qi::blank
- >> list_item
- ] [actions.list_item]
+ &qi::char_("*#")
+ >> +list_item
             ;
-
+
         list_item =
+ position
+ >> *qi::blank
+ >> qi::char_("*#")
+ >> qi::omit[*qi::blank]
+ >> list_item_content
+ ;
+
+ list_item_content =
+ qi::eps[actions.phrase_push] >>
            *( common
             | (qi::char_ -
                     ( qi::eol >> *qi::blank >> &(qi::char_('*') | '#')
@@ -406,6 +423,7 @@
                 ) [actions.plain_char]
             )
>> +eol
+ >> qi::eps[actions.phrase_pop]
             ;
 
         paragraph_end_markups =
@@ -435,9 +453,7 @@
                     phrase_end) [actions.plain_char]
             )
             ;
+
+ position = qi::raw[qi::eps] [get_position];
     }
 }
-
-#endif // BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP
-
-

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:20 EST (Wed, 27 Jan 2010)
@@ -129,98 +129,6 @@
         out << post;
     }
 
- void list_action::operator()(unused_type, unused_type, unused_type) const
- {
- 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())
- {
- char mark = list_marks.top().first;
- list_marks.pop();
- out << std::string((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
- if (list_marks.size() >= 1)
- out << std::string("\n</listitem>");
- }
-
- list_indent = -1; // reset
- }
-
- void list_format_action::operator()(iterator_range x, unused_type, unused_type) const
- {
- int new_indent = 0;
- iterator first = x.begin(), last = x.end();
- 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;
- }
- }
-
- char mark = *first;
- BOOST_ASSERT(mark == '#' || mark == '*'); // expecting a mark
-
- if (list_indent == -1) // the very start
- {
- BOOST_ASSERT(new_indent == 0);
- }
-
- if (new_indent > list_indent)
- {
- list_indent = new_indent;
- list_marks.push(mark_type(mark, list_indent));
- if (list_marks.size() > 1)
- {
- // 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.
-
- std::string str;
- out.swap(str);
- std::string::size_type pos = str.rfind("\n</listitem>");
- BOOST_ASSERT(pos <= str.size());
- str.erase(str.begin()+pos, str.end());
- out << str;
- }
- out << std::string((mark == '#') ? "<orderedlist>\n" : "<itemizedlist>\n");
- }
-
- 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();
- out << std::string((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
- if (list_marks.size() >= 1)
- out << std::string("\n</listitem>");
- }
- }
-
- if (mark != list_marks.top().first) // new_indent == list_indent
- {
- boost::spirit::classic::file_position const pos = first.get_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;
- ++error_count;
- }
- }
-
     void span::operator()(iterator_range x, unused_type, unused_type) const
     {
         iterator first = x.begin(), last = x.end();
@@ -1035,5 +943,13 @@
     {
         phrase.swap(out);
     }
+
+ void output_action::operator()(unused_type, unused_type, unused_type) const
+ {
+ std::string out;
+ actions.phrase.swap(out);
+ actions.out << out;
+ }
+
 }
 

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:20 EST (Wed, 27 Jan 2010)
@@ -179,52 +179,6 @@
         macro_symbols const& macro;
     };
 
- 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)
- : out(out)
- , list_buffer(list_buffer)
- , list_indent(list_indent)
- , list_marks(list_marks) {}
-
- void operator()(unused_type, unused_type, unused_type) const;
-
- collector& out;
- collector& list_buffer;
- int& list_indent;
- std::stack<mark_type>& list_marks;
- };
-
- 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)
- : out(out)
- , list_indent(list_indent)
- , list_marks(list_marks)
- , error_count(error_count) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& out;
- int& list_indent;
- std::stack<mark_type>& list_marks;
- int& error_count;
- };
-
     struct span
     {
         // Decorates c++ code fragments
@@ -713,6 +667,16 @@
         
         quickbook::actions& actions;
     };
+
+ struct output_action
+ {
+ output_action(quickbook::actions& actions)
+ : actions(actions) {}
+
+ void operator()(unused_type, unused_type, unused_type) const;
+
+ quickbook::actions& actions;
+ };
 }
 
 #ifdef BOOST_MSVC

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:20 EST (Wed, 27 Jan 2010)
@@ -39,7 +39,6 @@
 
     // auxilliary streams
         , phrase()
- , list_buffer()
 
     // state
         , filename(fs::complete(fs::path(filein_, fs::native)))
@@ -54,14 +53,13 @@
         , table_span(0)
         , table_header()
         , macro_id()
- , list_marks()
- , list_indent(-1)
         , template_info()
         , template_depth(0)
         , templates()
         , error_count(0)
 
     // actions
+ , output(*this)
         , process(*this)
         , phrase_push(phrase)
         , phrase_pop(phrase)
@@ -92,10 +90,6 @@
         , plain_char(phrase)
         , raw_char(phrase)
 
- , list(out, list_buffer, list_indent, list_marks)
- , list_format(list_buffer, list_indent, list_marks, error_count)
- , list_item(list_buffer, phrase, list_item_pre, list_item_post)
-
         , variablelist(*this)
         , start_varlistentry(phrase, start_varlistentry_)
         , end_varlistentry(phrase, end_varlistentry_)
@@ -153,7 +147,6 @@
         out.push();
         phrase.push();
         temp_para.push();
- list_buffer.push();
         templates.push();
     }
 
@@ -173,7 +166,6 @@
         out.pop();
         phrase.pop();
         temp_para.pop();
- list_buffer.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:20 EST (Wed, 27 Jan 2010)
@@ -54,7 +54,6 @@
     // auxilliary streams
         collector phrase;
         collector temp_para;
- collector list_buffer;
 
     // state
         fs::path filename;
@@ -95,6 +94,7 @@
     ///////////////////////////////////////////////////////////////////////////
     // actions
     ///////////////////////////////////////////////////////////////////////////
+ output_action output;
         process_action process;
         phrase_push_action phrase_push;
         phrase_pop_action phrase_pop;
@@ -114,10 +114,6 @@
         plain_char_action plain_char;
         raw_char_action raw_char;
 
- list_action list;
- list_format_action list_format;
- phrase_action list_item;
-
         variablelist_action variablelist;
         markup_action start_varlistentry;
         markup_action end_varlistentry;

Modified: branches/quickbook-1.5-spirit2/parse_utils.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/parse_utils.hpp (original)
+++ branches/quickbook-1.5-spirit2/parse_utils.hpp 2010-01-27 17:02:20 EST (Wed, 27 Jan 2010)
@@ -14,6 +14,7 @@
 
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_function.hpp>
+#include <boost/spirit/include/support_attributes.hpp>
 #include <string>
 
 namespace quickbook
@@ -30,9 +31,18 @@
         }
     };
     
+ struct get_position_impl
+ {
+ template <typename Range, typename Context>
+ void operator()(Range const& it, Context& c, bool& x) const {
+ boost::spirit::_val(it, c, x) = it.begin().get_position();
+ }
+ };
+
     namespace ph = boost::phoenix;
 
     namespace {
+ get_position_impl get_position;
         ph::function<as_string_impl> as_string;
     }
 }

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:20 EST (Wed, 27 Jan 2010)
@@ -94,14 +94,6 @@
     namespace qi = boost::spirit::qi;
     namespace ph = boost::phoenix;
     
- struct get_position_impl
- {
- template <typename Context>
- void operator()(iterator_range& it, Context& c, unused_type x) const {
- qi::_val(it, c, x) = it.begin().get_position();
- }
- } get_position;
-
     struct phrase_grammar::rules
     {
         rules(quickbook::actions& actions, bool& no_eols);


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