|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65207 - in branches/quickbook-1.5-spirit2: . src
From: dnljms_at_[hidden]
Date: 2010-09-03 04:01:41
Author: danieljames
Date: 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
New Revision: 65207
URL: http://svn.boost.org/trac/boost/changeset/65207
Log:
Merge position iterator optimization.
A little slower, as there are some extra unnecessary copies. Also perhaps the
horrible workaround for stacking macros.
Properties modified:
branches/quickbook-1.5-spirit2/ (props changed)
Text files modified:
branches/quickbook-1.5-spirit2/src/block_actions.cpp | 2 +-
branches/quickbook-1.5-spirit2/src/fwd.hpp | 4 ++--
branches/quickbook-1.5-spirit2/src/template.cpp | 16 +++++++++++-----
branches/quickbook-1.5-spirit2/src/template.hpp | 5 +++--
branches/quickbook-1.5-spirit2/src/template_grammar.cpp | 28 ++++++++++++++++++++++++----
5 files changed, 41 insertions(+), 14 deletions(-)
Modified: branches/quickbook-1.5-spirit2/src/block_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/src/block_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/src/block_actions.cpp 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
@@ -246,7 +246,7 @@
if (err != 0)
return err; // return early on error
- iterator first(code.begin(), code.end(), file);
+ iterator first(code.begin(), code.end(), file.c_str());
iterator last(code.end(), code.end());
size_t fname_len = file.size();
Modified: branches/quickbook-1.5-spirit2/src/fwd.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/src/fwd.hpp (original)
+++ branches/quickbook-1.5-spirit2/src/fwd.hpp 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
@@ -29,9 +29,9 @@
struct rule_store;
+ typedef boost::spirit::classic::file_position_base<char const*> file_position;
typedef boost::spirit::classic::position_iterator<
- std::string::const_iterator> iterator;
- typedef boost::spirit::classic::file_position file_position;
+ std::string::const_iterator, file_position> iterator;
typedef boost::iterator_range<iterator> raw_source;
struct raw_string;
Modified: branches/quickbook-1.5-spirit2/src/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/src/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/src/template.cpp 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
@@ -209,7 +209,7 @@
bool break_arguments(
std::vector<template_body>& args
, std::vector<std::string> const& params
- , boost::spirit::classic::file_position const& pos
+ , quickbook::file_position const& pos
)
{
// Quickbook 1.4-: If there aren't enough parameters seperated by
@@ -230,7 +230,9 @@
// arguments, or if there are no more spaces left.
template_body& body = args.back();
- iterator begin(body.content.begin(), body.content.end(), body.position.file);
+ iterator begin(body.content.begin(), body.content.end(),
+ file_position(body.position.file.c_str(),
+ body.position.line, body.position.column));
iterator end(body.content.end(), body.content.end());
iterator l_pos = find_first_seperator(begin, end);
@@ -242,7 +244,7 @@
while(r_pos != end && std::find(whitespace, whitespace_end, *r_pos) != whitespace_end) ++r_pos;
if (r_pos == end)
break;
- template_body second(std::string(r_pos, end), begin.get_position(), false);
+ template_body second(std::string(r_pos, end), r_pos.get_position(), false);
body.content = std::string(begin, l_pos);
args.push_back(second);
}
@@ -320,7 +322,9 @@
quickbook_grammar g(actions);
// do a phrase level parse
- iterator first(body.content.begin(), body.content.end(), body.position);
+ iterator first(body.content.begin(), body.content.end(),
+ file_position(body.position.file.c_str(),
+ body.position.line, body.position.column));
iterator last(body.content.end(), body.content.end());
bool r = boost::spirit::qi::parse(first, last, g.simple_phrase) && first == last;
// do a phrase level parse
@@ -339,7 +343,9 @@
// the need to check for end of file in the grammar.
std::string content = body.content + "\n\n";
- iterator first(content.begin(), content.end(), body.position);
+ iterator first(content.begin(), content.end(),
+ file_position(body.position.file.c_str(),
+ body.position.line, body.position.column));
iterator last(content.end(), content.end());
bool r = boost::spirit::qi::parse(first, last, g.block) && first == last;
state.paragraph_output();
Modified: branches/quickbook-1.5-spirit2/src/template.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/src/template.hpp (original)
+++ branches/quickbook-1.5-spirit2/src/template.hpp 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
@@ -19,6 +19,7 @@
namespace quickbook
{
namespace qi = boost::spirit::qi;
+ namespace cl = boost::spirit::classic;
struct template_scope;
struct template_symbol;
@@ -33,12 +34,12 @@
)
:
content(content),
- position(position),
+ position(position.file, position.line, position.column),
is_block(is_block)
{}
std::string content;
- quickbook::file_position position;
+ cl::file_position position;
bool is_block;
};
Modified: branches/quickbook-1.5-spirit2/src/template_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/src/template_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/src/template_grammar.cpp 2010-09-03 04:01:39 EDT (Fri, 03 Sep 2010)
@@ -22,7 +22,27 @@
{
namespace qi = boost::spirit::qi;
namespace repo = boost::spirit::repository;
-
+ namespace cl = boost::spirit::classic;
+
+ namespace {
+ // template_body contains cl::file_position (storing the file name in a
+ // std::string). But the grammar uses quickbook::file_position (storing
+ // the file name in a C string for efficiency). So a special action is
+ // needed to set the position.
+ // Better solution: use an intermediate type.
+ // Possibly even better solution: use a custom const string type.
+
+ struct template_body_position_type {
+ template <typename Context>
+ void operator()(quickbook::file_position const& attrib, Context& context, bool& pass) const {
+ (spirit::_val)(attrib,context,pass).position =
+ cl::file_position(attrib.file, attrib.line, attrib.column);
+ }
+ };
+
+ template_body_position_type template_body_position;
+ }
+
struct template_grammar_local
{
qi::rule<iterator, quickbook::define_template()> define_template;
@@ -58,7 +78,7 @@
;
local.template_body =
- position [member_assign(&quickbook::template_body::position)]
+ position [template_body_position]
>> qi::matches[&(*qi::blank >> qi::eol)]
[member_assign(&quickbook::template_body::is_block)]
>> qi::raw[local.template_body_recurse]
@@ -96,7 +116,7 @@
qi::eps(qbk_since(105u)) >> -(local.template_arg_1_5 % "..");
local.template_arg_1_4 =
- position [member_assign(&quickbook::template_body::position)]
+ position [template_body_position]
>> qi::matches[&(*qi::blank >> qi::eol)]
[member_assign(&quickbook::template_body::is_block)]
>> qi::raw[+(local.brackets_1_4 | ~qi::char_(']') - "..")]
@@ -109,7 +129,7 @@
;
local.template_arg_1_5 =
- position [member_assign(&quickbook::template_body::position)]
+ position [template_body_position]
>> qi::matches[&(*qi::blank >> qi::eol)]
[member_assign(&quickbook::template_body::is_block)]
>> qi::raw[+(local.brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
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