Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60134 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-03-03 18:30:00


Author: danieljames
Date: 2010-03-03 18:29:59 EST (Wed, 03 Mar 2010)
New Revision: 60134
URL: http://svn.boost.org/trac/boost/changeset/60134

Log:
Store if a template is a block template or not at the time of
definition.

Makes callouts easier to implement as it doesn't have to fake a block,
tracks the location better and will make it easier to be smarter about
block templates.
Text files modified:
   branches/quickbook-1.5-spirit2/template.cpp | 72 ++++++++++++++++++---------------------
   1 files changed, 33 insertions(+), 39 deletions(-)

Modified: branches/quickbook-1.5-spirit2/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/template.cpp 2010-03-03 18:29:59 EST (Wed, 03 Mar 2010)
@@ -25,28 +25,20 @@
         template_symbol(
                 std::string const& identifier,
                 std::vector<std::string> const& params,
- template_value const& body,
- template_scope const* parent)
- : identifier(identifier)
- , params(params)
- , body(body)
- , parent(parent) {}
-
- template_symbol(
- std::string const& identifier,
- std::vector<std::string> const& params,
+ bool is_block,
                 template_value const& body,
                 quickbook::callouts const& callouts,
                 template_scope const* parent)
            : identifier(identifier)
            , params(params)
+ , is_block(is_block)
            , body(body)
            , callouts(callouts)
            , parent(parent) {}
 
-
         std::string identifier;
         std::vector<std::string> params;
+ bool is_block;
         template_value body;
         quickbook::callouts callouts;
         template_scope const* parent;
@@ -131,9 +123,17 @@
             return false;
         }
 
+ std::string::const_iterator
+ iter = definition.body.content.begin(),
+ end = definition.body.content.end();
+ while (iter != end && ((*iter == ' ') || (*iter == '\t')))
+ ++iter; // skip spaces and tabs
+ bool is_block = (iter != end) && ((*iter == '\r') || (*iter == '\n'));
+
         template_symbol ts(
             definition.id,
             definition.params,
+ is_block,
             definition.body,
             definition.callouts,
             parent ? parent : &top_scope());
@@ -300,7 +300,8 @@
         }
 
         bool parse_template(
- std::string body
+ bool is_block
+ , std::string body
           , std::string& result
           , file_position const& template_pos
           , bool template_escape
@@ -312,12 +313,6 @@
             // a newline, then we regard it as a block, otherwise, we parse
             // it as a phrase.
             
- body.reserve(body.size() + 2);
-
- std::string::const_iterator iter = body.begin();
- while (iter != body.end() && ((*iter == ' ') || (*iter == '\t')))
- ++iter; // skip spaces and tabs
- bool is_block = (iter != body.end()) && ((*iter == '\r') || (*iter == '\n'));
             bool r = false;
 
             if (template_escape)
@@ -348,11 +343,16 @@
                 // ensure that we have enough trailing newlines to eliminate
                 // the need to check for end of file in the grammar.
                 body += "\n\n";
- while (iter != body.end() && ((*iter == '\r') || (*iter == '\n')))
- ++iter; // skip initial newlines
- iterator first(iter, body.end(), state.filename.native_file_string().c_str());
+
+ iterator first(body.begin(), body.end(), state.filename.native_file_string().c_str());
                 first.set_position(template_pos);
                 iterator last(body.end(), body.end());
+
+ while (first != last && ((*first == ' ') || (*first == '\t')))
+ ++first; // skip spaces and tabs
+ while (first != last && ((*first == '\r') || (*first == '\n')))
+ ++first; // skip initial newlines
+
                 r = boost::spirit::qi::parse(first, last, block_p) && first == last;
                 state.phrase.swap(result);
             }
@@ -424,7 +424,7 @@
             ///////////////////////////////////
             // parse the template body:
 
- if (!parse_template(x.symbol->body.content, result, x.symbol->body.position, x.escape, state))
+ if (!parse_template(x.symbol->is_block, 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
@@ -459,24 +459,18 @@
                 callout_item item;
                 item.identifier = c.identifier;
                 
- std::size_t pos = c.body.content.find_first_not_of(" \t\n\r");
- if(pos != std::string::npos) {
- std::string content = "\n";
- content.append(c.body.content, pos, c.body.content.size() - pos);
-
- state.push();
- // TODO: adjust the position?
- bool r = parse_template(content, item.content, c.body.position, false, state);
- state.pop();
+ state.push();
+ // TODO: adjust the position?
+ bool r = parse_template(true, c.body.content, item.content, c.body.position, false, state);
+ state.pop();
 
- if(!r)
- {
- detail::outerr(c.body.position.file, c.body.position.line)
- << "Error expanding callout."
- << std::endl;
- ++state.error_count;
- return "";
- }
+ if(!r)
+ {
+ detail::outerr(c.body.position.file, c.body.position.line)
+ << "Error expanding callout."
+ << std::endl;
+ ++state.error_count;
+ return "";
                 }
 
                 list.push_back(item);


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