|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57779 - in branches/quickbook-1.5-spirit2: . detail test
From: daniel_james_at_[hidden]
Date: 2009-11-18 18:20:45
Author: danieljames
Date: 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
New Revision: 57779
URL: http://svn.boost.org/trac/boost/changeset/57779
Log:
Use synthesized attributes for template calls.
Text files modified:
branches/quickbook-1.5-spirit2/detail/actions.cpp | 58 ++++++++++++++++-----------------------
branches/quickbook-1.5-spirit2/detail/actions.hpp | 5 ++
branches/quickbook-1.5-spirit2/detail/template_stack.hpp | 4 +-
branches/quickbook-1.5-spirit2/grammars.hpp | 9 ++---
branches/quickbook-1.5-spirit2/phrase.hpp | 52 ++++++++++++-----------------------
branches/quickbook-1.5-spirit2/test/templates_1_4.gold | 2
6 files changed, 53 insertions(+), 77 deletions(-)
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 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -598,7 +598,7 @@
}
bool break_arguments(
- std::vector<std::string>& template_info
+ std::vector<std::string>& params
, std::vector<std::string> const& template_
, boost::spirit::classic::file_position const& pos
)
@@ -610,17 +610,17 @@
// then use whitespace to separate them
// (2 = template name + argument).
- if (qbk_version_n < 105 || template_info.size() == 2)
+ if (qbk_version_n < 105 || params.size() == 1)
{
- // template_.size() - 1 because template_ also includes the body.
- while (template_info.size() < template_.size()-1 )
+ // template_.size() - 2 because template_ also includes the name and body.
+ while (params.size() < template_.size() - 2 )
{
// Try to break the last argument at the first space found
- // and push it into the back of template_info. Do this
+ // and push it into the back of params. Do this
// recursively until we have all the expected number of
// arguments, or if there are no more spaces left.
- std::string& str = template_info.back();
+ std::string& str = params.back();
std::string::size_type l_pos = find_first_seperator(str);
if (l_pos == std::string::npos)
break;
@@ -630,17 +630,17 @@
break;
std::string second(str.begin()+r_pos, str.end());
str = first;
- template_info.push_back(second);
+ params.push_back(second);
}
}
- if (template_info.size() != template_.size()-1)
+ if (params.size() != template_.size() - 2)
{
detail::outerr(pos.file, pos.line)
<< "Invalid number of arguments passed. Expecting: "
<< template_.size()-2
<< " argument(s), got: "
- << template_info.size()-1
+ << params.size()
<< " argument(s) instead."
<< std::endl;
return false;
@@ -650,18 +650,18 @@
std::pair<bool, std::vector<std::string>::const_iterator>
get_arguments(
- std::vector<std::string>& template_info
+ std::vector<std::string>& params
, std::vector<std::string> const& template_
, template_scope const& scope
, boost::spirit::classic::file_position const& pos
, quickbook::actions& actions
)
{
- std::vector<std::string>::const_iterator arg = template_info.begin()+1;
+ std::vector<std::string>::const_iterator arg = params.begin();
std::vector<std::string>::const_iterator tpl = template_.begin()+1;
// Store each of the argument passed in as local templates:
- while (arg != template_info.end())
+ while (arg != params.end())
{
std::vector<std::string> tinfo;
tinfo.push_back(*tpl);
@@ -688,6 +688,7 @@
std::string& body
, std::string& result
, boost::spirit::classic::file_position const& template_pos
+ , bool template_escape
, quickbook::actions& actions
)
{
@@ -705,7 +706,7 @@
bool is_block = (iter != body.end()) && ((*iter == '\r') || (*iter == '\n'));
bool r = false;
- if (actions.template_escape)
+ if (template_escape)
{
// escape the body of the template
// we just copy out the literal body
@@ -740,9 +741,10 @@
}
}
- void do_template_action::operator()(iterator_range x, unused_type, unused_type) const
+ void do_template_action::operator()(iterator p, bool template_escape,
+ template_symbol const& symbol, std::vector<std::string> params) const
{
- boost::spirit::classic::file_position const pos = x.begin().get_position();
+ boost::spirit::classic::file_position const pos = p.get_position();
++actions.template_depth;
if (actions.template_depth > actions.max_template_depth)
{
@@ -760,33 +762,22 @@
// arguments are expanded.
template_scope const& call_scope = actions.templates.top_scope();
- template_symbol const* symbol =
- actions.templates.find(actions.template_info[0]);
- BOOST_ASSERT(symbol);
-
std::string result;
actions.push(); // scope the actions' states
{
- template_symbol const* symbol =
- actions.templates.find(actions.template_info[0]);
- BOOST_ASSERT(symbol);
-
// Quickbook 1.4-: When expanding the tempalte continue to use the
// current scope (the dynamic scope).
// Quickbook 1.5+: Use the scope the template was defined in
// (the static scope).
if (qbk_version_n >= 105)
- actions.templates.set_parent_scope(*boost::get<2>(*symbol));
-
- std::vector<std::string> template_ = boost::get<0>(*symbol);
- boost::spirit::classic::file_position template_pos = boost::get<1>(*symbol);
+ actions.templates.set_parent_scope(*boost::get<2>(symbol));
- std::vector<std::string> template_info;
- std::swap(template_info, actions.template_info);
+ std::vector<std::string> template_ = boost::get<0>(symbol);
+ boost::spirit::classic::file_position template_pos = boost::get<1>(symbol);
///////////////////////////////////
// Break the arguments
- if (!break_arguments(template_info, template_, pos))
+ if (!break_arguments(params, template_, pos))
{
actions.pop(); // restore the actions' states
--actions.template_depth;
@@ -799,7 +790,7 @@
bool get_arg_result;
std::vector<std::string>::const_iterator tpl;
boost::tie(get_arg_result, tpl) =
- get_arguments(template_info, template_,
+ get_arguments(params, template_,
call_scope, pos, actions);
if (!get_arg_result)
@@ -815,11 +806,10 @@
body.assign(tpl->begin(), tpl->end());
body.reserve(body.size()+2); // reserve 2 more
- if (!parse_template(body, result, template_pos, actions))
+ if (!parse_template(body, result, template_pos, template_escape, actions))
{
- boost::spirit::classic::file_position const pos = x.begin().get_position();
detail::outerr(pos.file,pos.line)
- << "Expanding template:" << template_info[0] << std::endl
+ //<< "Expanding template:" << template_info[0] << std::endl
<< "------------------begin------------------" << std::endl
<< body
<< "------------------end--------------------" << std::endl
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 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -555,12 +555,15 @@
struct do_template_action
{
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ struct result { typedef void type; };
+
// Handles template substitutions
do_template_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(iterator_range, unused_type, unused_type) const;
+ void operator()(iterator, bool, template_symbol const&, std::vector<std::string>) const;
quickbook::actions& actions;
};
Modified: branches/quickbook-1.5-spirit2/detail/template_stack.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/template_stack.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/template_stack.hpp 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -70,7 +70,7 @@
{
template <typename Ctx, typename Itr>
struct attribute {
- typedef template_scope type;
+ typedef template_symbol type;
};
parser(template_stack& ts)
@@ -83,7 +83,7 @@
boost::spirit::qi::skip_over(first, last, skipper);
// TODO: Is this right?
- Attribute result_attr;
+ template_symbol result_attr;
// search all scopes for the longest matching symbol.
Iterator f = first;
Modified: branches/quickbook-1.5-spirit2/grammars.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammars.hpp (original)
+++ branches/quickbook-1.5-spirit2/grammars.hpp 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -34,13 +34,12 @@
simple_bold, simple_italic, simple_underline,
simple_teletype, source_mode, template_,
quote, code_block, footnote, replaceable, macro,
- dummy_block, cond_phrase, macro_identifier, template_args,
- template_args_1_4, template_arg_1_4, brackets_1_4,
- template_args_1_5, template_arg_1_5,
- template_inner_arg_1_5, brackets_1_5
+ dummy_block, cond_phrase, macro_identifier,
+ brackets_1_4, template_inner_arg_1_5, brackets_1_5
;
- qi::rule<Iterator, std::string()> image_filename;
+ qi::rule<Iterator, std::string()> image_filename, template_arg_1_4, template_arg_1_5;
+ qi::rule<Iterator, std::vector<std::string>() > template_args;
};
template <typename Iterator, typename Actions>
Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -20,6 +20,9 @@
#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_fusion.hpp>
+#include <boost/spirit/include/phoenix_bind.hpp>
+#include <boost/fusion/include/make_fused.hpp>
namespace quickbook
{
@@ -113,53 +116,34 @@
>> actions.macro [actions.do_macro]
;
- static const bool true_ = true;
- static const bool false_ = false;
+ // Template call
template_ =
- (
- qi::char_('`') [ph::ref(actions.template_escape) = true_]
- |
- qi::eps [ph::ref(actions.template_escape) = false_]
- )
- >>
- ( (
- qi::raw[&qi::punct >> actions.templates.scope]
- [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- >> -template_args
- ) | (
- qi::raw[actions.templates.scope] [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- >> -(hard_space >> template_args)
- ) )
- >> &qi::lit(']')
+ ( qi::raw[qi::eps] // For the position of the template
+ >> -qi::char_('`') // Attribute implicitly cast to bool
+ >> ( // Lookup the template name
+ (&qi::punct >> actions.templates.scope)
+ | (actions.templates.scope >> hard_space)
+ )
+ >> template_args
+ >> &qi::lit(']')
+ ) [ph::bind(actions.do_template, ph::begin(qi::_1), qi::_2, qi::_3, qi::_4)]
;
template_args =
- qi::eps(qbk_before(105u)) >> template_args_1_4
- |
- qi::eps(qbk_since(105u)) >> template_args_1_5
- ;
-
- template_args_1_4 =
- qi::raw[template_arg_1_4] [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- % ".."
- ;
+ qi::eps(qbk_before(105u)) >> -(template_arg_1_4 % "..") |
+ qi::eps(qbk_since(105u)) >> -(template_arg_1_5 % "..");
template_arg_1_4 =
- +(brackets_1_4 | (qi::char_ - (qi::lit("..") | ']')))
+ qi::raw[+(brackets_1_4 | (qi::char_ - (qi::lit("..") | ']')))]
;
brackets_1_4 =
'[' >> +template_arg_1_4 >> ']'
;
- template_args_1_5 =
- qi::raw[template_arg_1_5] [ph::push_back(ph::ref(actions.template_info), as_string(qi::_1))]
- % ".."
- ;
-
template_arg_1_5 =
- +(brackets_1_5 | ('\\' >> qi::char_) | (qi::char_ - (qi::lit("..") | '[' | ']')))
+ qi::raw[+(brackets_1_5 | ('\\' >> qi::char_) | (qi::char_ - (qi::lit("..") | '[' | ']')))]
;
template_inner_arg_1_5 =
@@ -248,7 +232,7 @@
| quote
| replaceable
| footnote
- | qi::raw[template_] [actions.do_template]
+ | template_
| qi::raw["br"] [actions.break_]
)
>> ']'
Modified: branches/quickbook-1.5-spirit2/test/templates_1_4.gold
==============================================================================
--- branches/quickbook-1.5-spirit2/test/templates_1_4.gold (original)
+++ branches/quickbook-1.5-spirit2/test/templates_1_4.gold 2009-11-18 18:20:41 EST (Wed, 18 Nov 2009)
@@ -15,7 +15,7 @@
{1-2} {1-2} {1-2 3 4} {1 2-3 4} {1 2 3-4} {[1-2} {1..2-3} {1..2-3}
</para>
<para>
- {[binary 1 2- {1 2-y}} 4]
+ {[binary 1 2-3} 4]
</para>
<para>
{1-2-3} {1-2-3} {1-2-3 4} {1 2-3-4} {[1-2-3}
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