Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75261 - in branches/quickbook-dev/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2011-11-02 04:47:03


Author: danieljames
Date: 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
New Revision: 75261
URL: http://svn.boost.org/trac/boost/changeset/75261

Log:
Quickbook: Store template_body as just a value.
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 72 ++++++++++++++++++---------------------
   branches/quickbook-dev/tools/quickbook/src/template_stack.cpp | 16 --------
   branches/quickbook-dev/tools/quickbook/src/template_stack.hpp | 37 ++++----------------
   branches/quickbook-dev/tools/quickbook/src/values.cpp | 34 ++++++++----------
   branches/quickbook-dev/tools/quickbook/src/values.hpp | 4 +-
   branches/quickbook-dev/tools/quickbook/test/unit/values_test.cpp | 2
   6 files changed, 60 insertions(+), 105 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -1065,7 +1065,7 @@
         }
     
         void break_arguments(
- std::vector<template_body>& args
+ std::vector<value>& args
           , std::vector<std::string> const& params
           , fs::path const& filename
         )
@@ -1087,36 +1087,36 @@
                     // recursively until we have all the expected number of
                     // arguments, or if there are no more spaces left.
 
- template_body& body = args.back();
- string_iterator begin = body.content.get_quickbook().begin();
- string_iterator end = body.content.get_quickbook().end();
+ value last_arg = args.back();
+ string_iterator begin = last_arg.get_quickbook().begin();
+ string_iterator end = last_arg.get_quickbook().end();
                     
                     std::pair<string_iterator, string_iterator> pos =
                         find_seperator(begin, end);
                     if (pos.second == end) break;
- template_body second(
- qbk_value_ref(body.content.get_file(),
+ value new_arg(
+ qbk_value_ref(last_arg.get_file(),
                             pos.second, end, template_tags::phrase));
     
                     // TODO: Make sure that this is overwriting a reference, not
                     // a value.
- body.content = qbk_value_ref(body.content.get_file(),
- begin, pos.first, body.content.get_tag());
- args.push_back(second);
+ args.back() = qbk_value_ref(last_arg.get_file(),
+ begin, pos.first, last_arg.get_tag());
+ args.push_back(new_arg);
                 }
             }
         }
 
         std::pair<bool, std::vector<std::string>::const_iterator>
         get_arguments(
- std::vector<template_body> const& args
+ std::vector<value> const& args
           , std::vector<std::string> const& params
           , template_scope const& scope
           , string_iterator first
           , quickbook::actions& actions
         )
         {
- std::vector<template_body>::const_iterator arg = args.begin();
+ std::vector<value>::const_iterator arg = args.begin();
             std::vector<std::string>::const_iterator tpl = params.begin();
             std::vector<std::string> empty_params;
 
@@ -1137,22 +1137,20 @@
         }
         
         bool parse_template(
- template_body const& body
+ value const& content
           , quickbook::actions& actions
         )
         {
- assert(body.type != template_body::raw_output);
-
             file const* saved_current_file = actions.current_file;
 
- actions.current_file = body.content.get_file();
- string_ref source = body.content.get_quickbook();
+ actions.current_file = content.get_file();
+ string_ref source = content.get_quickbook();
 
             parse_iterator first(source.begin());
             parse_iterator last(source.end());
 
             bool r = cl::parse(first, last,
- body.is_block() ?
+ content.get_tag() == template_tags::block ?
                         actions.grammar().block :
                         actions.grammar().simple_phrase
                 ).full;
@@ -1165,7 +1163,7 @@
 
     void call_template(quickbook::actions& actions,
             template_symbol const* symbol,
- std::vector<template_body> const& args,
+ std::vector<value> const& args,
             string_iterator first)
     {
         // The template arguments should have the scope that the template was
@@ -1181,7 +1179,7 @@
         {
             template_state state(actions);
 
- qbk_version_n = symbol->body.content.get_file()->version();
+ qbk_version_n = symbol->content.get_file()->version();
 
             ++actions.template_depth;
             if (actions.template_depth > actions.max_template_depth)
@@ -1218,15 +1216,15 @@
             ///////////////////////////////////
             // parse the template body:
 
- if (!parse_template(symbol->body, actions))
+ if (!parse_template(symbol->content, actions))
             {
                 detail::outerr(actions.current_file, first)
                     << "Expanding "
- << (symbol->body.is_block() ? "block" : "phrase")
+ << (symbol->content.get_tag() == template_tags::block ? "block" : "phrase")
                     << " template: " << detail::utf8(symbol->identifier) << std::endl
                     << std::endl
                     << "------------------begin------------------" << std::endl
- << detail::utf8(symbol->body.content.get_quickbook())
+ << detail::utf8(symbol->content.get_quickbook())
                     << "------------------end--------------------" << std::endl
                     << std::endl;
                 ++actions.error_count;
@@ -1247,7 +1245,7 @@
             actions.phrase.swap(phrase);
         }
 
- if(symbol->body.is_block() || !block.empty()) {
+ if(symbol->content.get_tag() == template_tags::block || !block.empty()) {
             actions.paragraph(); // For paragraphs before the template call.
             actions.out << block;
             actions.phrase << phrase;
@@ -1262,10 +1260,10 @@
             template_symbol const* symbol,
             string_iterator first)
     {
- assert(symbol->body.is_block());
+ assert(symbol->content.get_tag() == template_tags::block);
 
         std::vector<std::string> callout_ids;
- std::vector<template_body> args;
+ std::vector<value> args;
         unsigned int size = symbol->params.size();
         std::string callout_base("c");
 
@@ -1278,9 +1276,7 @@
             code += "<co id=\"" + callout_id1 + "\" ";
             code += "linkends=\"" + callout_id2 + "\" />";
 
- args.push_back(template_body(
- bbk_value(code, template_tags::phrase),
- template_body::raw_output));
+ args.push_back(bbk_value(code, template_tags::phrase));
             callout_ids.push_back(callout_id1);
             callout_ids.push_back(callout_id2);
         }
@@ -1303,7 +1299,7 @@
                     template_state state(actions);
                     ++actions.template_depth;
 
- bool r = parse_template(template_body(c), actions);
+ bool r = parse_template(c, actions);
 
                     if(!r)
                     {
@@ -1343,12 +1339,11 @@
 
         std::string identifier = values.consume(template_tags::identifier).get_quickbook();
 
- std::vector<std::string> callout_ids;
- std::vector<template_body> args;
+ std::vector<value> args;
 
         BOOST_FOREACH(value arg, values)
         {
- args.push_back(template_body(arg));
+ args.push_back(arg);
         }
         
         values.finish();
@@ -1358,11 +1353,10 @@
 
         // Deal with raw templates and escaped templates.
 
- if (symbol->body.type == template_body::raw_output)
+ if (symbol->content.is_encoded())
         {
- // Note: 'raw_output' is currently only used for callouts in code_snippets.
- (symbol->body.is_block() ? actions.out : actions.phrase)
- << symbol->body.content.get_boostbook();
+ (symbol->content.get_tag() == template_tags::block ? actions.out : actions.phrase)
+ << symbol->content.get_boostbook();
             return;
         }
         else if (template_escape)
@@ -1375,8 +1369,8 @@
                 ++actions.error_count;
             }
 
- (symbol->body.is_block() ? actions.out : actions.phrase)
- << symbol->body.content.get_quickbook();
+ (symbol->content.get_tag() == template_tags::block ? actions.out : actions.phrase)
+ << symbol->content.get_quickbook();
             return;
         }
 
@@ -1868,7 +1862,7 @@
                 ts.parent = &actions.templates.top_scope();
                 if (!actions.templates.add(ts))
                 {
- detail::outerr(ts.body.content.get_file(), ts.body.content.get_position())
+ detail::outerr(ts.content.get_file(), ts.content.get_position())
                         << "Template Redefinition: " << detail::utf8(tname) << std::endl;
                     ++actions.error_count;
                 }

Modified: branches/quickbook-dev/tools/quickbook/src/template_stack.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/template_stack.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/template_stack.cpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -16,22 +16,6 @@
 
 namespace quickbook
 {
- template_body::template_body(
- value const& content,
- content_type type
- )
- : content(content)
- , type(type)
- {
- assert(content.get_tag() == template_tags::block ||
- content.get_tag() == template_tags::phrase);
- }
-
- bool template_body::is_block() const
- {
- return content.get_tag() == template_tags::block;
- }
-
     template_stack::template_stack()
         : scope(template_stack::parser(*this))
         , scopes()

Modified: branches/quickbook-dev/tools/quickbook/src/template_stack.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/template_stack.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/template_stack.hpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -12,6 +12,7 @@
 #include <string>
 #include <deque>
 #include <vector>
+#include <cassert>
 #include <boost/tuple/tuple.hpp>
 #include <boost/assert.hpp>
 #include <boost/spirit/include/classic_functor_parser.hpp>
@@ -26,36 +27,10 @@
 {
     namespace fs = boost::filesystem;
 
- struct template_body
- {
- enum content_type
- {
- quickbook,
- raw_output
- };
-
- template_body(value const&, content_type = quickbook);
- bool is_block() const;
-
- value content;
- content_type type;
- };
-
     struct template_scope;
 
     struct template_symbol
     {
- template_symbol(
- std::string const& identifier,
- std::vector<std::string> const& params,
- template_body const& body,
- template_scope const* parent = 0)
- : identifier(identifier)
- , params(params)
- , body(body)
- , parent(parent)
- , callouts() {}
-
            template_symbol(
                 std::string const& identifier,
                 std::vector<std::string> const& params,
@@ -63,13 +38,17 @@
                 template_scope const* parent = 0)
            : identifier(identifier)
            , params(params)
- , body(content)
+ , content(content)
            , parent(parent)
- , callouts() {}
+ , callouts()
+ {
+ assert(content.get_tag() == template_tags::block ||
+ content.get_tag() == template_tags::phrase);
+ }
 
         std::string identifier;
         std::vector<std::string> params;
- template_body body;
+ value content;
         
         // This is only used for quickbook 1.5+, 1.4 uses the dynamic scope.
         // TODO: I should probably call this something like lexical_parent

Modified: branches/quickbook-dev/tools/quickbook/src/values.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/values.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/values.cpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -58,7 +58,7 @@
         bool value_node::empty() const { return false; }
         bool value_node::check() const { return true; }
         bool value_node::is_list() const { return false; }
- bool value_node::is_string() const { return false; }
+ bool value_node::is_encoded() const { return false; }
         bool value_node::equals(value_node*) const { UNDEFINED_ERROR(); }
     }
 
@@ -89,7 +89,7 @@
             bool empty() const { UNDEFINED_ERROR(); }
             bool check() const { UNDEFINED_ERROR(); }
             bool is_list() const { UNDEFINED_ERROR(); }
- bool is_string() const { UNDEFINED_ERROR(); }
+ bool is_encoded() const { UNDEFINED_ERROR(); }
         };
 
         value_list_end_impl value_list_end_impl::instance;
@@ -245,6 +245,7 @@
             virtual int get_int() const;
             virtual std::string get_boostbook() const;
             virtual bool empty() const;
+ virtual bool is_encoded() const;
             virtual bool equals(value_node*) const;
 
             int value_;
@@ -275,6 +276,11 @@
             return false;
         }
 
+ bool value_int_impl::is_encoded() const
+ {
+ return true;
+ }
+
         bool value_int_impl::equals(value_node* other) const {
             try {
                 return value_ == other->get_int();
@@ -305,8 +311,8 @@
             virtual ~value_string_impl();
             virtual value_node* clone() const;
             virtual std::string get_boostbook() const;
- virtual bool is_string() const;
             virtual bool empty() const;
+ virtual bool is_encoded() const;
             virtual bool equals(value_node*) const;
 
             std::string value_;
@@ -325,7 +331,6 @@
             virtual file const* get_file() const;
             virtual string_iterator get_position() const;
             virtual string_ref get_quickbook() const;
- virtual bool is_string() const;
             virtual bool empty() const;
             virtual bool equals(value_node*) const;
 
@@ -348,7 +353,6 @@
             virtual file const* get_file() const;
             virtual string_iterator get_position() const;
             virtual string_ref get_quickbook() const;
- virtual bool is_string() const;
             virtual bool empty() const;
             virtual bool equals(value_node*) const;
 
@@ -372,8 +376,8 @@
             virtual string_iterator get_position() const;
             virtual string_ref get_quickbook() const;
             virtual std::string get_boostbook() const;
- virtual bool is_string() const;
             virtual bool empty() const;
+ virtual bool is_encoded() const;
             virtual bool equals(value_node*) const;
 
             file const* file_;
@@ -408,12 +412,12 @@
         std::string value_string_impl::get_boostbook() const
             { return value_; }
 
- bool value_string_impl::is_string() const
- { return true; }
-
         bool value_string_impl::empty() const
             { return value_.empty(); }
 
+ bool value_string_impl::is_encoded() const
+ { return true; }
+
         bool value_string_impl::equals(value_node* other) const {
             try {
                 return value_ == other->get_boostbook();
@@ -458,9 +462,6 @@
         string_ref value_qbk_string_impl::get_quickbook() const
             { return string_ref(fake_file_.source); }
 
- bool value_qbk_string_impl::is_string() const
- { return true; }
-
         bool value_qbk_string_impl::empty() const
             { return fake_file_.source.empty(); }
 
@@ -502,9 +503,6 @@
         string_ref value_qbk_ref_impl::get_quickbook() const
             { return string_ref(begin_, end_); }
 
- bool value_qbk_ref_impl::is_string() const
- { return true; }
-
         bool value_qbk_ref_impl::empty() const
             { return begin_ == end_; }
     
@@ -556,13 +554,13 @@
         std::string value_qbk_bbk_impl::get_boostbook() const
             { return bbk_value_; }
 
- bool value_qbk_bbk_impl::is_string() const
- { return true; }
-
         // Should this test the quickbook, the boostbook or both?
         bool value_qbk_bbk_impl::empty() const
             { return bbk_value_.empty(); }
 
+ bool value_qbk_bbk_impl::is_encoded() const
+ { return true; }
+
         bool value_qbk_bbk_impl::equals(value_node* other) const {
             try {
                 return this->get_quickbook() == other->get_quickbook();

Modified: branches/quickbook-dev/tools/quickbook/src/values.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/values.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/values.hpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -56,8 +56,8 @@
 
             virtual bool check() const;
             virtual bool empty() const;
+ virtual bool is_encoded() const;
             virtual bool is_list() const;
- virtual bool is_string() const;
             virtual bool equals(value_node*) const;
 
             virtual value_node* get_list() const;
@@ -100,8 +100,8 @@
         public:
             bool check() const { return value_->check(); }
             bool empty() const { return value_->empty(); }
+ bool is_encoded() const { return value_->is_encoded(); }
             bool is_list() const { return value_->is_list(); }
- bool is_string() const { return value_->is_string(); }
 
             iterator begin() const;
             iterator end() const;

Modified: branches/quickbook-dev/tools/quickbook/test/unit/values_test.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/unit/values_test.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/test/unit/values_test.cpp 2011-11-02 04:47:01 EDT (Wed, 02 Nov 2011)
@@ -20,7 +20,7 @@
     quickbook::value q;
     BOOST_TEST(q.empty());
     BOOST_TEST(!q.is_list());
- BOOST_TEST(!q.is_string());
+ BOOST_TEST(!q.is_encoded());
 }
 
 void qbk_tests()


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