Boost logo

Boost-Commit :

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


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

Log:
Paragraphs, sections, titles.
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 1
   branches/quickbook-1.5-spirit2/block.cpp | 127 ++++++++++++++++++++++++++++++---------
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 69 ---------------------
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 20 ------
   branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 2
   branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 2
   6 files changed, 97 insertions(+), 124 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:31 EST (Wed, 27 Jan 2010)
@@ -32,6 +32,7 @@
     phrase_image.cpp
     phrase_template.cpp
     block.cpp
+ block_actions.cpp
     block_list.cpp
     doc_info.cpp
     detail/syntax_highlight.cpp

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:31 EST (Wed, 27 Jan 2010)
@@ -17,13 +17,21 @@
 #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/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_container.hpp>
 #include <boost/spirit/include/phoenix_bind.hpp>
+#include <boost/spirit/include/phoenix_fusion.hpp>
 #include <boost/fusion/include/adapt_struct.hpp>
 
 BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::paragraph,
+ (std::string, content)
+ (char const*, dummy)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
     quickbook::list_item,
     (quickbook::file_position, position)
     (std::string, indent)
@@ -31,6 +39,24 @@
     (std::string, content)
 )
 
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::title,
+ (std::string, raw_markup)
+ (std::string, content)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::begin_section,
+ (boost::optional<std::string>, id)
+ (quickbook::title, content)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::end_section,
+ (quickbook::file_position, position)
+ (char const*, dummy)
+)
+
 namespace quickbook
 {
     namespace qi = boost::spirit::qi;
@@ -43,25 +69,38 @@
         quickbook::actions& actions;
         bool no_eols;
         phrase_grammar common;
- qi::symbols<> paragraph_end_markups;
         qi::rule<iterator>
                         start_, blocks, block_markup, code, code_line,
- paragraph, space, blank, comment, headings, h, h1, h2,
- h3, h4, h5, h6, hr, blurb, blockquote, admonition,
+ space, blank, comment, headings, h, h1, h2,
+ h3, h4, h5, h6, blurb, blockquote, admonition,
                         phrase, phrase_end, ordered_list, def_macro,
                         macro_identifier, table, table_row, variablelist,
                         varlistentry, varlistterm, varlistitem, table_cell,
- preformatted, begin_section, end_section,
+ preformatted,
                         xinclude, include, hard_space, eol, paragraph_end,
                         template_, template_id, template_formal_arg,
                         template_body, identifier, dummy_block, import,
                         inside_paragraph;
 
+ qi::symbols<> paragraph_end_markups;
+ qi::rule<iterator, quickbook::paragraph()> paragraph;
+ qi::rule<iterator, std::string()> paragraph_content;
+
         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, quickbook::hr()> hr;
+
+ qi::rule<iterator, boost::optional<std::string>()> element_id, element_id_1_5;
+ qi::rule<iterator, std::string()> element_id_part;
 
- qi::rule<iterator, boost::optional<std::string>()> element_id, element_id_1_5;
+ qi::rule<iterator, quickbook::begin_section()> begin_section;
+ qi::rule<iterator, quickbook::end_section()> end_section;
+
+ qi::rule<iterator, quickbook::title()> title_phrase;
+ qi::rule<iterator, std::string()> phrase_attr;
+
         qi::rule<iterator, file_position()> position;
     };
 
@@ -83,9 +122,9 @@
            +( block_markup
             | code
             | list [actions.process][actions.output]
- | hr [actions.hr]
+ | hr [actions.process][actions.output]
             | comment >> *eol
- | paragraph [actions.paragraph]
+ | paragraph [actions.process][actions.output]
             | eol
             )
             ;
@@ -121,15 +160,17 @@
             ;
 
         hr =
- qi::lit("----")
- >> *(qi::char_ - eol)
- >> +eol
+ qi::omit[
+ "----"
+ >> *(qi::char_ - eol)
+ >> +eol
+ ] >> qi::attr(quickbook::hr())
             ;
 
         block_markup =
                 '[' >> space
- >> ( begin_section
- | end_section
+ >> ( begin_section [actions.process][actions.output]
+ | end_section [actions.process][actions.output]
                 | headings
                 | blurb
                 | blockquote
@@ -149,28 +190,33 @@
             ;
         
         element_id =
- -(
- ':'
+ ( ':'
>> -(qi::eps(qbk_since(105u)) >> space)
>> (
- (+(qi::alnum | qi::char_('_'))) [qi::_val = as_string(qi::_1)]
- | qi::raw[qi::eps] [actions.element_id_warning]
+ element_id_part
+ | qi::omit[
+ qi::raw[qi::eps] [actions.element_id_warning]
+ ]
                 )
- );
+ )
+ | qi::eps
+ ;
 
+ element_id_part = +(qi::alnum | qi::char_('_'));
         
- element_id_1_5 =
- -(qi::eps(qbk_since(105u)) >> element_id [qi::_val = qi::_1]);
+ element_id_1_5 = (qi::eps(qbk_since(105u)) >> element_id) | qi::eps;
 
- begin_section = (
- "section"
- >> hard_space
- >> element_id
- >> qi::raw[phrase]) [ph::bind(actions.begin_section, qi::_1, qi::_2)]
+ begin_section =
+ "section"
+ >> hard_space
+ >> element_id
+ >> title_phrase
             ;
 
         end_section =
- qi::raw["endsect"] [actions.end_section]
+ position
+ >> "endsect"
+ >> qi::attr("dummy")
             ;
 
         headings =
@@ -437,15 +483,34 @@
             '[' >> space >> paragraph_end_markups >> hard_space | eol >> eol
             ;
 
- paragraph =
- *( common
- | (qi::char_ - // Make sure we don't go past
- paragraph_end // a single block.
- ) [actions.plain_char]
- )
+ paragraph_content =
+ qi::eps [actions.phrase_push]
+ >> *( common
+ | (qi::char_ - // Make sure we don't go past
+ paragraph_end // a single block.
+ ) [actions.plain_char]
+ )
+ >> qi::eps [actions.phrase_pop]
>> (&qi::lit('[') | +eol)
             ;
 
+ paragraph = paragraph_content >> qi::attr("dummy");
+
+ title_phrase =
+ qi::raw[
+ phrase_attr [ph::at_c<1>(qi::_val) = qi::_1]
+ ] [ph::at_c<0>(qi::_val) = as_string(qi::_1)]
+ ;
+
+ phrase_attr =
+ qi::eps [actions.phrase_push]
+ >> *( common
+ | comment
+ | (qi::char_ - phrase_end) [actions.plain_char]
+ )
+ >> qi::eps [actions.phrase_pop]
+ ;
+
         phrase =
            *( common
             | comment

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:31 EST (Wed, 27 Jan 2010)
@@ -377,75 +377,6 @@
         phrase << str << end_cell_;
     }
 
- void begin_section_action::operator()(boost::optional<std::string> const& id, iterator_range x) const
- {
- section_id = id ? *id :
- detail::make_identifier(x.begin(), x.end());
-
- if (section_level != 0)
- qualified_section_id += '.';
- else
- BOOST_ASSERT(qualified_section_id.empty());
- qualified_section_id += section_id;
- ++section_level;
-
- if (qbk_version_n < 103) // version 1.2 and below
- {
- out << "\n<section id=\""
- << library_id << "." << section_id << "\">\n";
- }
- else // version 1.3 and above
- {
- out << "\n<section id=\"" << library_id
- << "." << qualified_section_id << "\">\n";
- }
- std::string str;
- phrase.swap(str);
-
- if (qbk_version_n < 103) // version 1.2 and below
- {
- out << "<title>" << str << "</title>\n";
- }
- else // version 1.3 and above
- {
- out << "<title>"
- << "<link linkend=\"" << library_id
- << "." << qualified_section_id << "\">"
- << str
- << "</link>"
- << "</title>\n"
- ;
- }
- }
-
- void end_section_action::operator()(iterator_range x, unused_type, unused_type) const
- {
- out << "</section>";
-
- --section_level;
- if (section_level < 0)
- {
- boost::spirit::classic::file_position const pos = x.begin().get_position();
- detail::outerr(pos.file,pos.line)
- << "Mismatched [endsect] near column " << pos.column << ".\n";
- ++error_count;
-
- // $$$ TODO: somehow fail parse else BOOST_ASSERT(std::string::npos != n)
- // $$$ below will assert.
- }
- if (section_level == 0)
- {
- qualified_section_id.clear();
- }
- else
- {
- std::string::size_type const n =
- qualified_section_id.find_last_of('.');
- BOOST_ASSERT(std::string::npos != n);
- qualified_section_id.erase(n, std::string::npos);
- }
- }
-
     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:31 EST (Wed, 27 Jan 2010)
@@ -469,26 +469,6 @@
         std::string& qualified_section_id;
     };
 
- struct end_section_action
- {
- end_section_action(
- collector& out
- , int& section_level
- , std::string& qualified_section_id
- , int& error_count)
- : out(out)
- , section_level(section_level)
- , qualified_section_id(qualified_section_id)
- , error_count(error_count) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& out;
- int& section_level;
- std::string& qualified_section_id;
- int& error_count;
- };
-
    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:31 EST (Wed, 27 Jan 2010)
@@ -111,8 +111,6 @@
         , start_cell(phrase, table_span)
         , end_cell(phrase, temp_para)
 
- , begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id)
- , end_section(out, section_level, qualified_section_id, error_count)
         , xinclude(out, *this)
         , include(*this)
         , import(out, *this)

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:31 EST (Wed, 27 Jan 2010)
@@ -135,8 +135,6 @@
         start_col_action start_cell;
         end_col_action end_cell;
 
- begin_section_action begin_section;
- end_section_action end_section;
         element_id_warning_action element_id_warning;
         xinclude_action xinclude;
         include_action include;


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