Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59668 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-02-13 10:03:57


Author: danieljames
Date: 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
New Revision: 59668
URL: http://svn.boost.org/trac/boost/changeset/59668

Log:
Store the position of template parameters as well as the body.
Text files modified:
   branches/quickbook-1.5-spirit2/block.cpp | 13 ++++++++---
   branches/quickbook-1.5-spirit2/block_actions.cpp | 4 +-
   branches/quickbook-1.5-spirit2/code_snippet.cpp | 2
   branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp | 4 ++
   branches/quickbook-1.5-spirit2/phrase.cpp | 29 ++++++++++++++-----------
   branches/quickbook-1.5-spirit2/phrase.hpp | 7 ------
   branches/quickbook-1.5-spirit2/template.cpp | 44 ++++++++++++++++++++-------------------
   branches/quickbook-1.5-spirit2/template.hpp | 31 +++++++++++++++++++++++----
   8 files changed, 80 insertions(+), 54 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-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -71,8 +71,13 @@
     quickbook::define_template,
     (std::string, id)
     (std::vector<std::string>, params)
+ (quickbook::template_value, body)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::template_value,
     (quickbook::file_position, position)
- (std::string, body)
+ (std::string, content)
 )
 
 BOOST_FUSION_ADAPT_STRUCT(
@@ -138,7 +143,7 @@
         qi::rule<iterator, quickbook::include()> include;
         qi::rule<iterator, quickbook::import()> import;
         qi::rule<iterator, quickbook::define_template()> define_template;
- qi::rule<iterator, std::string()> template_body;
+ qi::rule<iterator, quickbook::template_value()> template_body;
         qi::rule<iterator> template_body_recurse;
         qi::rule<iterator, quickbook::code()> code;
         qi::rule<iterator> code_line;
@@ -385,12 +390,12 @@
>> space
>> ']'
                 )
- >> position
>> template_body
             ;
 
         template_body =
- qi::raw[template_body_recurse]
+ position
+ >> qi::raw[template_body_recurse]
             ;
 
         template_body_recurse =

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-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -155,7 +155,7 @@
     nothing process(quickbook::state& state, define_template const& x)
     {
         if(!state.templates.add(x)) {
- detail::outerr(x.position.file, x.position.line)
+ detail::outerr(x.body.position.file, x.body.position.line)
                 << "Template Redefinition: " << x.id << std::endl;
             ++state.error_count;
         }
@@ -354,7 +354,7 @@
         {
             if (!state.templates.add(definition))
             {
- detail::outerr(definition.position.file, definition.position.line)
+ detail::outerr(definition.body.position.file, definition.body.position.line)
                     << "Template Redefinition: " << definition.id << std::endl;
                 ++state.error_count;
             }

Modified: branches/quickbook-1.5-spirit2/code_snippet.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet.cpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet.cpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -104,7 +104,7 @@
 
         std::vector<std::string> empty_params;
         actions.storage.push_back(define_template(
- x.identifier, empty_params, actions.snippet, x.position));
+ x.identifier, empty_params, template_value(x.position, actions.snippet)));
 
         callout_id += actions.callouts.size();
         actions.callouts.clear();

Modified: branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -40,8 +40,10 @@
             start_, ignore;
         qi::rule<iterator, quickbook::code_snippet()>
             snippet;
+ qi::rule<iterator>
+ code_elements;
         qi::rule<iterator, std::string()>
- code_elements, identifier;
+ identifier;
         qi::rule<iterator, quickbook::callout()>
             inline_callout, line_callout;
         qi::rule<iterator, quickbook::escaped_comment()>

Modified: branches/quickbook-1.5-spirit2/phrase.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.cpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -67,7 +67,13 @@
     (quickbook::file_position, position)
     (bool, escape)
     (quickbook::template_symbol const*, symbol)
- (std::vector<std::string>, args)
+ (std::vector<quickbook::template_value>, args)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::template_value,
+ (quickbook::file_position, position)
+ (std::string, content)
 )
 
 namespace quickbook
@@ -111,11 +117,10 @@
         qi::symbols<char, formatted_type> format_symbol;
         qi::rule<iterator, quickbook::formatted()> footnote;
         qi::rule<iterator, quickbook::call_template()> call_template;
- qi::rule<iterator, std::vector<std::string>() > template_args;
- qi::rule<iterator, std::string()> template_arg_1_4;
+ qi::rule<iterator, std::vector<quickbook::template_value>()> template_args;
+ qi::rule<iterator, quickbook::template_value()> template_arg_1_4;
         qi::rule<iterator> brackets_1_4;
- qi::rule<iterator, std::string()> template_arg_1_5;
- qi::rule<iterator> template_inner_arg_1_5;
+ qi::rule<iterator, quickbook::template_value()> template_arg_1_5;
         qi::rule<iterator> brackets_1_5;
         qi::rule<iterator, quickbook::break_()> break_;
         qi::rule<iterator> space, blank, eol, phrase_end, hard_space;
@@ -402,23 +407,21 @@
             qi::eps(qbk_since(105u)) >> -(template_arg_1_5 % "..");
 
         template_arg_1_4 =
- qi::raw[+(brackets_1_4 | (qi::char_ - (qi::lit("..") | ']')))]
+ position >>
+ qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
             ;
 
         brackets_1_4 =
- '[' >> +template_arg_1_4 >> ']'
+ '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
             ;
 
         template_arg_1_5 =
- qi::raw[+(brackets_1_5 | ('\\' >> qi::char_) | (qi::char_ - (qi::lit("..") | '[' | ']')))]
- ;
-
- template_inner_arg_1_5 =
- +(brackets_1_5 | ('\\' >> qi::char_) | (qi::char_ - (qi::lit('[') | ']')))
+ position >>
+ qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
             ;
 
         brackets_1_5 =
- '[' >> +template_inner_arg_1_5 >> ']'
+ '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
             ;
 
         break_ =

Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -25,13 +25,6 @@
         std::string mode;
     };
     
- struct call_template {
- file_position position;
- bool escape;
- template_symbol const* symbol;
- std::vector<std::string> args;
- };
-
     struct anchor {
         std::string id;
     };

Modified: branches/quickbook-1.5-spirit2/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/template.cpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -25,19 +25,16 @@
         template_symbol(
                 std::string const& identifier,
                 std::vector<std::string> const& params,
- std::string const& body,
- file_position const& position,
+ template_value const& body,
                 template_scope const* parent)
            : identifier(identifier)
            , params(params)
            , body(body)
- , position(position)
            , parent(parent) {}
     
         std::string identifier;
         std::vector<std::string> params;
- std::string body;
- file_position position;
+ template_value body;
         template_scope const* parent;
     };
 
@@ -124,7 +121,6 @@
             definition.id,
             definition.params,
             definition.body,
- definition.position,
             parent ? parent : &top_scope());
 
         scopes.front().symbols.add(ts.identifier.c_str(), ts);
@@ -202,7 +198,7 @@
         }
     
         bool break_arguments(
- std::vector<std::string>& args
+ std::vector<template_value>& args
           , std::vector<std::string> const& params
           , file_position const& pos
         )
@@ -223,15 +219,22 @@
                     // recursively until we have all the expected number of
                     // arguments, or if there are no more spaces left.
 
- std::string& str = args.back();
- std::string::size_type l_pos = find_first_seperator(str);
+ template_value& str = args.back();
+ std::string::size_type l_pos = find_first_seperator(str.content);
                     if (l_pos == std::string::npos)
                         break;
- std::string first(str.begin(), str.begin()+l_pos);
- std::string::size_type r_pos = str.find_first_not_of(" \t\r\n", l_pos);
+ template_value first(
+ str.position,
+ std::string(str.content.begin(), str.content.begin() + l_pos)
+ );
+ std::string::size_type r_pos = str.content.find_first_not_of(" \t\r\n", l_pos);
                     if (r_pos == std::string::npos)
                         break;
- std::string second(str.begin()+r_pos, str.end());
+ // TODO: Work out position?
+ template_value second(
+ str.position,
+ std::string(str.content.begin()+r_pos, str.content.end())
+ );
                     str = first;
                     args.push_back(second);
                 }
@@ -253,23 +256,22 @@
 
         std::pair<bool, std::vector<std::string>::const_iterator>
         get_arguments(
- std::vector<std::string>& args
+ std::vector<template_value>& args
           , std::vector<std::string> const& params
           , template_scope const& scope
           , file_position const& pos
           , quickbook::state& state
         )
         {
- std::vector<std::string>::const_iterator arg = args.begin();
+ std::vector<template_value>::const_iterator arg = args.begin();
             std::vector<std::string>::const_iterator tpl = params.begin();
+ std::vector<std::string> empty_params;
 
             // Store each of the argument passed in as local templates:
             while (arg != args.end())
             {
- std::vector<std::string> empty_params;
-
                 if (!state.templates.add(
- define_template(*tpl, empty_params, *arg, pos),
+ define_template(*tpl, empty_params, *arg),
                         &scope))
                 {
                     detail::outerr(pos.file,pos.line)
@@ -372,7 +374,7 @@
             if (qbk_version_n >= 105)
                 state.templates.set_parent_scope(*x.symbol->parent);
 
- std::vector<std::string> args = x.args;
+ std::vector<template_value> args = x.args;
     
             ///////////////////////////////////
             // Break the arguments
@@ -402,13 +404,13 @@
             ///////////////////////////////////
             // parse the template body:
 
- if (!parse_template(x.symbol->body, result, x.symbol->position, x.escape, state))
+ if (!parse_template(x.symbol->body.content, result, x.symbol->body.position, x.escape, state))
             {
                 detail::outerr(x.position.file,x.position.line)
- //<< "Expanding template:" << x.symbol->identifier << std::endl
+ << "Expanding template:" << x.symbol->identifier << std::endl
                     << std::endl
                     << "------------------begin------------------" << std::endl
- << x.symbol->body
+ << x.symbol->body.content
                     << "------------------end--------------------" << std::endl
                     << std::endl;
                 state.pop(); // restore the state

Modified: branches/quickbook-1.5-spirit2/template.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.hpp (original)
+++ branches/quickbook-1.5-spirit2/template.hpp 2010-02-13 10:03:56 EST (Sat, 13 Feb 2010)
@@ -20,6 +20,21 @@
 {
     namespace qi = boost::spirit::qi;
 
+ struct template_value
+ {
+ template_value() {}
+ template_value(
+ quickbook::file_position position,
+ std::string const& content)
+ :
+ position(position),
+ content(content)
+ {}
+
+ quickbook::file_position position;
+ std::string content;
+ };
+
     struct define_template
     {
         define_template() {}
@@ -27,16 +42,22 @@
         define_template(
             std::string id,
             std::vector<std::string> params,
- std::string body,
- quickbook::file_position position)
+ template_value body
+ )
         :
- id(id), params(params), body(body), position(position)
+ id(id), params(params), body(body)
         {}
 
         std::string id;
         std::vector<std::string> params;
- std::string body;
- quickbook::file_position position;
+ template_value body;
+ };
+
+ struct call_template {
+ file_position position;
+ bool escape;
+ template_symbol const* symbol;
+ std::vector<template_value> args;
     };
 
     struct template_scope;


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