Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59307 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-01-27 17:03:18


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

Log:
Define templates.
Text files modified:
   branches/quickbook-1.5-spirit2/block.cpp | 66 +++++++++++++++++++++++++++------------
   branches/quickbook-1.5-spirit2/block.hpp | 13 +++++++
   branches/quickbook-1.5-spirit2/block_actions.cpp | 18 ++++++++++
   branches/quickbook-1.5-spirit2/block_list.cpp | 5 +-
   4 files changed, 77 insertions(+), 25 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:03:17 EST (Wed, 27 Jan 2010)
@@ -73,6 +73,14 @@
 )
 
 BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::define_template,
+ (std::string, id)
+ (std::vector<std::string>, params)
+ (quickbook::file_position, position)
+ (std::string, body)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
     quickbook::variablelist,
     (std::string, title)
     (std::vector<quickbook::varlistentry>, entries)
@@ -102,14 +110,13 @@
                         space, blank, comment,
                         phrase, phrase_end, ordered_list,
                         xinclude, include, hard_space, eol, paragraph_end,
- template_, template_id, template_formal_arg,
- template_body, identifier, dummy_block, import;
+ dummy_block, import;
 
         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()> list;
         qi::rule<iterator, quickbook::list_item()> list_item;
         qi::rule<iterator, std::string()> list_item_content;
         
@@ -133,6 +140,13 @@
         qi::rule<iterator, std::string()> macro_identifier;
         qi::rule<iterator, quickbook::def_macro()> def_macro;
 
+ qi::rule<iterator, quickbook::define_template()> define_template;
+ qi::rule<iterator, std::string()> identifier;
+ qi::rule<iterator, std::string()> punctuation_identifier;
+ qi::rule<iterator, std::string()> template_id;
+ qi::rule<iterator, std::string()> template_body;
+ qi::rule<iterator> template_body_recurse;
+
         qi::rule<iterator, quickbook::variablelist()> variablelist;
         qi::rule<iterator, quickbook::varlistentry()> varlistentry;
         qi::rule<iterator, quickbook::formatted()>
@@ -228,7 +242,7 @@
                 | xinclude
                 | include
                 | import
- | template_
+ | define_template [actions.process][actions.output]
                 )
>> ( (space >> ']' >> +eol)
                 | error
@@ -337,30 +351,40 @@
         identifier =
             (qi::alpha | '_') >> *(qi::alnum | '_')
             ;
+
+ punctuation_identifier =
+ qi::repeat(1)[qi::punct - (qi::char_('[') | ']')]
+ ;
 
         template_id =
- identifier | (qi::punct - (qi::char_('[') | ']'))
+ identifier | punctuation_identifier
             ;
 
- template_ =
- "template"
- >> hard_space >> qi::raw[template_id]
- [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- >>
- -(
- space >> '['
- >> *(
- space >> qi::raw[template_id]
- [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- )
- >> space >> ']'
- )
- >> qi::raw[template_body] [actions.template_body]
+ define_template =
+ "template"
+ >> hard_space
+ >> template_id
+ >> -(
+ space
+ >> '['
+ >> *(space >> template_id)
+ >> space
+ >> ']'
+ )
+ >> position
+ >> template_body
             ;
 
         template_body =
- *(('[' >> template_body >> ']') | (qi::char_ - ']'))
- >> space >> &qi::lit(']')
+ qi::raw[template_body_recurse]
+ ;
+
+ template_body_recurse =
+ *( ('[' >> template_body_recurse >> ']')
+ | (qi::char_ - ']')
+ )
+ >> space
+ >> &qi::lit(']')
             ;
 
         variablelist =

Modified: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.hpp (original)
+++ branches/quickbook-1.5-spirit2/block.hpp 2010-01-27 17:03:17 EST (Wed, 27 Jan 2010)
@@ -39,6 +39,8 @@
         std::string content;
     };
 
+ typedef std::vector<list_item> list;
+
     struct title
     {
         std::string raw_markup;
@@ -63,6 +65,14 @@
         title content;
     };
 
+ struct define_template
+ {
+ std::string id;
+ std::vector<std::string> params;
+ quickbook::file_position position;
+ std::string body;
+ };
+
     struct def_macro
     {
         std::string macro_identifier;
@@ -89,11 +99,12 @@
     
     void process(quickbook::actions&, hr);
     void process(quickbook::actions&, paragraph const&);
- void process(quickbook::actions&, std::vector<list_item> const&);
+ void process(quickbook::actions&, list 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&, def_macro const&);
+ void process(quickbook::actions&, define_template const&);
     void process(quickbook::actions&, variablelist const&);
     void process(quickbook::actions&, table const&);
 }

Modified: branches/quickbook-1.5-spirit2/block_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.cpp 2010-01-27 17:03:17 EST (Wed, 27 Jan 2010)
@@ -175,6 +175,24 @@
 
     }
 
+ void process(quickbook::actions& actions, define_template const& x)
+ {
+ if (actions.templates.find_top_scope(x.id))
+ {
+ detail::outerr(x.position.file, x.position.line)
+ << "Template Redefinition: " << actions.template_info[0] << std::endl;
+ ++actions.error_count;
+ }
+
+ std::vector<std::string> info;
+ info.reserve(x.params.size() + 2);
+ info.push_back(x.id);
+ info.insert(info.end(), x.params.begin(), x.params.end());
+ info.push_back(x.body);
+
+ actions.templates.add(x.id, template_symbol(info, x.position));
+ }
+
     void process(quickbook::actions& actions, variablelist const& x)
     {
         actions.phrase << "<variablelist>\n";

Modified: branches/quickbook-1.5-spirit2/block_list.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_list.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_list.cpp 2010-01-27 17:03:17 EST (Wed, 27 Jan 2010)
@@ -35,13 +35,12 @@
         }
     }
 
- void process(quickbook::actions& actions, std::vector<list_item> const& list)
+ void process(quickbook::actions& actions, quickbook::list 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)
+ for(list::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
         {
             int new_indent = indent_length(it->indent);
             BOOST_ASSERT(it->mark == '#' || it->mark == '*');


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