|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68885 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-14 19:22:22
Author: danieljames
Date: 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
New Revision: 68885
URL: http://svn.boost.org/trac/boost/changeset/68885
Log:
Use values for calling templates.
Added:
branches/quickbook-filenames/tools/quickbook/src/template_tags.hpp (contents, props changed)
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 42 ++++++++++++++++++++++---------------
branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 12 ----------
branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 6 ++--
branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 4 ---
branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 45 +++++++++++++++++----------------------
5 files changed, 48 insertions(+), 61 deletions(-)
Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -21,6 +21,7 @@
#include "actions_class.hpp"
#include "grammar.hpp"
#include "input_path.hpp"
+#include "template_tags.hpp"
namespace quickbook
{
@@ -903,29 +904,36 @@
int callout_id = 0;
}
- void template_arg_action::operator()(iterator first, iterator last) const
+ void do_template_action::operator()(iterator first, iterator) const
{
if(actions.suppress) return;
- actions.template_args.push_back(
- template_body(
- std::string(first, last),
- actions.filename,
- first.get_position(),
- actions.template_block));
- }
+ file_position const pos = first.get_position();
+
+ // Get the arguments
+ value_consumer values = actions.values.get();
- void do_template_action::operator()(iterator first, iterator) const
- {
- if(actions.suppress) return;
+ bool template_escape = values.is(template_tags::escape);
+ if(template_escape) values.consume();
- // Get the arguments and clear values stored in action.
+ std::string identifier = values.consume(template_tags::identifier).get_quickbook();
std::vector<template_body> args;
- std::string identifier;
- std::swap(args, actions.template_args);
- std::swap(identifier, actions.template_identifier);
- file_position const pos = first.get_position();
+
+ BOOST_FOREACH(value arg, values)
+ {
+ BOOST_ASSERT(
+ arg.get_tag() == template_tags::block ||
+ arg.get_tag() == template_tags::phrase);
+
+ args.push_back(
+ template_body(
+ arg.get_quickbook(),
+ actions.filename,
+ arg.get_position(),
+ arg.get_tag() == template_tags::block
+ ));
+ }
++actions.template_depth;
if (actions.template_depth > actions.max_template_depth)
@@ -1025,7 +1033,7 @@
///////////////////////////////////
// parse the template body:
- if (!parse_template(symbol->body, actions.template_escape, actions))
+ if (!parse_template(symbol->body, template_escape, actions))
{
file_position const pos = first.get_position();
detail::outerr(actions.filename, pos.line)
Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -640,18 +640,6 @@
quickbook::actions& actions;
};
- struct template_arg_action
- {
- // Handles a template argument
-
- template_arg_action(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- quickbook::actions& actions;
- };
-
struct do_template_action
{
// Handles template substitutions
Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -66,7 +66,6 @@
, template_identifier()
, template_info()
, template_depth(0)
- , template_escape(false)
, templates()
, error_count(0)
, anchors()
@@ -176,7 +175,6 @@
, macro_definition(*this)
, do_macro(phrase, *this)
, template_body(*this)
- , template_arg(*this)
, do_template(*this)
, url_pre(phrase, url_pre_, *this)
, url_post(phrase, url_post_, *this)
@@ -237,7 +235,8 @@
out.push();
phrase.push();
list_buffer.push();
- templates.push();
+ templates.push();
+ values.builder.save();
}
// Pushing and popping the macro symbol table is pretty expensive, so
@@ -278,6 +277,7 @@
phrase.pop();
list_buffer.pop();
templates.pop();
+ values.builder.restore();
}
quickbook_grammar& actions::grammar() const {
Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -115,10 +115,7 @@
std::string template_identifier;
string_list template_info;
int template_depth;
- bool template_escape;
bool template_block;
- std::vector<quickbook::template_body>
- template_args;
template_stack templates;
int error_count;
string_list anchors;
@@ -231,7 +228,6 @@
macro_definition_action macro_definition;
do_macro_action do_macro;
template_body_action template_body;
- template_arg_action template_arg;
do_template_action do_template;
link_action url_pre;
markup_action url_post;
Modified: branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -11,6 +11,7 @@
#include "grammar_impl.hpp"
#include "actions_class.hpp"
#include "utils.hpp"
+#include "template_tags.hpp"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_confix.hpp>
#include <boost/spirit/include/classic_chset.hpp>
@@ -73,7 +74,7 @@
template_args,
template_args_1_4, template_arg_1_4,
template_inner_arg_1_4, brackets_1_4,
- template_args_1_5, template_arg_1_5,
+ template_args_1_5, template_arg_1_5, template_arg_1_5_content,
template_inner_arg_1_5, brackets_1_5,
command_line_macro_identifier, command_line_phrase,
dummy_block
@@ -225,31 +226,24 @@
>> actions.macro [actions.do_macro]
;
- static const bool true_ = true;
- static const bool false_ = false;
-
local.template_ =
- (
- cl::ch_p('`') [cl::assign_a(actions.template_escape,true_)]
- |
- cl::eps_p [cl::assign_a(actions.template_escape,false_)]
- )
+ cl::eps_p [actions.values.reset]
+ >> !cl::str_p("`") [actions.values.entry(template_tags::escape)]
>>
( (
(cl::eps_p(cl::punct_p)
>> actions.templates.scope
- ) [cl::assign_a(actions.template_identifier)]
- [cl::clear_a(actions.template_args)]
+ ) [actions.values.entry(template_tags::identifier)]
>> !local.template_args
) | (
(actions.templates.scope
>> cl::eps_p(hard_space)
- ) [cl::assign_a(actions.template_identifier)]
- [cl::clear_a(actions.template_args)]
+ ) [actions.values.entry(template_tags::identifier)]
>> space
>> !local.template_args
) )
>> cl::eps_p(']')
+ >> cl::eps_p [actions.do_template]
;
local.template_args =
@@ -263,11 +257,10 @@
local.template_args_1_4 = local.template_arg_1_4 >> *(".." >> local.template_arg_1_4);
local.template_arg_1_4 =
- ( cl::eps_p(*cl::blank_p >> cl::eol_p)
- [cl::assign_a(actions.template_block, true_)]
- | cl::eps_p [cl::assign_a(actions.template_block, false_)]
- )
- >> local.template_inner_arg_1_4 [actions.template_arg]
+ ( cl::eps_p(*cl::blank_p >> cl::eol_p)
+ >> local.template_inner_arg_1_4 [actions.values.entry(template_tags::block)]
+ | local.template_inner_arg_1_4 [actions.values.entry(template_tags::phrase)]
+ )
;
local.template_inner_arg_1_4 =
@@ -281,12 +274,14 @@
local.template_args_1_5 = local.template_arg_1_5 >> *(".." >> local.template_arg_1_5);
local.template_arg_1_5 =
- ( cl::eps_p(*cl::blank_p >> cl::eol_p)
- [cl::assign_a(actions.template_block, true_)]
- | cl::eps_p [cl::assign_a(actions.template_block, false_)]
- )
- >> (+(local.brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p("..") | '[' | ']'))))
- [actions.template_arg]
+ ( cl::eps_p(*cl::blank_p >> cl::eol_p)
+ >> local.template_arg_1_5_content [actions.values.entry(template_tags::block)]
+ | local.template_arg_1_5_content [actions.values.entry(template_tags::phrase)]
+ )
+ ;
+
+ local.template_arg_1_5_content =
+ +(local.brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p("..") | '[' | ']')))
;
local.template_inner_arg_1_5 =
@@ -373,7 +368,7 @@
>> ( local.element
>> cl::eps_p(local.check_element(element_info::in_phrase))
>> local.element_rule
- | local.template_ [actions.do_template]
+ | local.template_
| cl::str_p("br") [actions.break_]
)
>> ']'
Added: branches/quickbook-filenames/tools/quickbook/src/template_tags.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-filenames/tools/quickbook/src/template_tags.hpp 2011-02-14 19:22:20 EST (Mon, 14 Feb 2011)
@@ -0,0 +1,24 @@
+/*=============================================================================
+ Copyright (c) 2011 Daniel James
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#if !defined(BOOST_SPIRIT_QUICKBOOK_TEMPLATE_TAGS_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_TEMPLATE_TAGS_HPP
+
+#include "value_tags.hpp"
+
+namespace quickbook
+{
+ QUICKBOOK_VALUE_TAGS(template_tags, 0x100,
+ (escape)
+ (identifier)
+ (block)
+ (phrase)
+ )
+}
+
+#endif
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