Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63809 - in trunk/tools/quickbook: detail doc test
From: daniel_james_at_[hidden]
Date: 2010-07-10 07:24:55


Author: danieljames
Date: 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
New Revision: 63809
URL: http://svn.boost.org/trac/boost/changeset/63809

Log:
Generate different ids when reusing code snippets.

Generates the ids during template expansion instead of when parsing the
code snippet - so that different ids are used for different exapnsions.
Refs #4416
Text files modified:
   trunk/tools/quickbook/detail/actions.cpp | 99 ++++++++++++++++++++++++++++-----------
   trunk/tools/quickbook/detail/template_stack.hpp | 2
   trunk/tools/quickbook/doc/quickbook.qbk | 1
   trunk/tools/quickbook/test/callouts.gold | 22 ++++++++
   trunk/tools/quickbook/test/callouts.quickbook | 4 +
   5 files changed, 99 insertions(+), 29 deletions(-)

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
@@ -808,6 +808,11 @@
         }
     }
 
+ namespace detail
+ {
+ int callout_id = 0;
+ }
+
     void do_template_action::operator()(iterator first, iterator) const
     {
         // Get the arguments and clear values stored in action.
@@ -854,13 +859,56 @@
                 actions.templates.set_parent_scope(*symbol->parent);
 
             ///////////////////////////////////
- // Break the arguments
- if (!break_arguments(args, symbol->params, pos))
+ // Initialise the arguments
+
+ if (!symbol->callout)
             {
- actions.pop(); // restore the actions' states
- --actions.template_depth;
- ++actions.error_count;
- return;
+ // Break the arguments for a template
+
+ if (!break_arguments(args, symbol->params, pos))
+ {
+ actions.pop(); // restore the actions' states
+ --actions.template_depth;
+ ++actions.error_count;
+ return;
+ }
+ }
+ else
+ {
+ if (!args.empty())
+ {
+ detail::outerr(pos.file, pos.line)
+ << "Arguments for code snippet."
+ <<std::endl;
+ ++actions.error_count;
+
+ args.clear();
+ }
+
+ BOOST_ASSERT(symbol->params.size() % 2 == 0);
+ unsigned int size = symbol->params.size() / 2;
+
+ for(unsigned int i = 0; i < size; ++i)
+ {
+ std::string callout_id = actions.doc_id +
+ boost::lexical_cast<std::string>(detail::callout_id++);
+
+ std::string code;
+ code += "'''";
+ code += "<co id=\"" + callout_id + "co\" ";
+ code += "linkends=\"" + callout_id + "\" />";
+ code += "'''";
+
+ args.push_back(code);
+
+ code.clear();
+ code += "'''";
+ code += "<callout arearefs=\"" + callout_id + "co\" ";
+ code += "id=\"" + callout_id + "\">";
+ code += "'''";
+
+ args.push_back(code);
+ }
             }
 
             ///////////////////////////////////
@@ -1198,21 +1246,10 @@
         code += *first;
     }
 
- namespace detail
- {
- int callout_id = 0;
- }
-
     void code_snippet_actions::callout(iterator first, iterator last)
     {
- using detail::callout_id;
- code += "``'''";
- code += "<co id=\"";
- code += doc_id + boost::lexical_cast<std::string>(callout_id + callouts.size()) + "co\" ";
- code += "linkends=\"";
- code += doc_id + boost::lexical_cast<std::string>(callout_id + callouts.size()) + "\" />";
- code += "'''``";
-
+ code += "``[[callout" + boost::lexical_cast<std::string>(callouts.size()) + "]]``";
+
         callouts.push_back(std::string(first, last));
     }
 
@@ -1239,7 +1276,8 @@
 
     void code_snippet_actions::compile(iterator first, iterator last)
     {
- using detail::callout_id;
+ std::vector<std::string> params;
+
         if (!code.empty())
         {
             detail::unindent(code); // remove all indents
@@ -1252,29 +1290,32 @@
 
             if(callouts.size() > 0)
             {
+ std::vector<std::string> callout_items;
+
               snippet += "'''<calloutlist>'''";
               for (size_t i = 0; i < callouts.size(); ++i)
               {
- snippet += "'''<callout arearefs=\"";
- snippet += doc_id + boost::lexical_cast<std::string>(callout_id + i) + "co\" ";
- snippet += "id=\"";
- snippet += doc_id + boost::lexical_cast<std::string>(callout_id + i) + "\">";
- snippet += "'''";
-
+ std::string callout_template = "[callout" + boost::lexical_cast<std::string>(i) + "]";
+ std::string calloutitem_template = "[calloutitem" + boost::lexical_cast<std::string>(i) + "]";
+
+ snippet += "[" + calloutitem_template + "]";
                   snippet += "'''<para>'''";
                   snippet += callouts[i];
                   snippet += "\n";
                   snippet += "'''</para>'''";
                   snippet += "'''</callout>'''";
+
+ params.push_back(callout_template);
+ params.push_back(calloutitem_template);
               }
               snippet += "'''</calloutlist>'''";
             }
         }
 
- std::vector<std::string> empty_params;
- storage.push_back(template_symbol(id, empty_params, snippet, first.get_position()));
+ template_symbol symbol(id, params, snippet, first.get_position());
+ symbol.callout = true;
+ storage.push_back(symbol);
 
- callout_id += callouts.size();
         callouts.clear();
         code.clear();
         snippet.clear();

Modified: trunk/tools/quickbook/detail/template_stack.hpp
==============================================================================
--- trunk/tools/quickbook/detail/template_stack.hpp (original)
+++ trunk/tools/quickbook/detail/template_stack.hpp 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
@@ -32,12 +32,14 @@
                 boost::spirit::classic::file_position const& position,
                 template_scope const* parent = 0)
            : identifier(identifier)
+ , callout(false)
            , params(params)
            , body(body)
            , position(position)
            , parent(parent) {}
 
         std::string identifier;
+ bool callout;
         std::vector<std::string> params;
         std::string body;
         boost::spirit::classic::file_position position;

Modified: trunk/tools/quickbook/doc/quickbook.qbk
==============================================================================
--- trunk/tools/quickbook/doc/quickbook.qbk (original)
+++ trunk/tools/quickbook/doc/quickbook.qbk 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
@@ -210,6 +210,7 @@
     followed by whitespace or a list character.
   * Doesn't treat several consecutive blank lines as multiple paragraph breaks.
 * Fixes duplicate image attribute detection.
+* Fixes using code snippets more than once.
 * Early work on quickbook 1.6, available using the `[quickbook 1.6]` version switch,
   but liable to change in future versions.
   * When automatically generating ids for headers, use the quickbook

Modified: trunk/tools/quickbook/test/callouts.gold
==============================================================================
--- trunk/tools/quickbook/test/callouts.gold (original)
+++ trunk/tools/quickbook/test/callouts.gold 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
@@ -66,4 +66,26 @@
   <para>
     </para></callout></calloutlist>
   </para>
+ <para>
+ Example 3 (again!):
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+ <!--quickbook-escape-prefix--><co id="callout_tests3co" linkends="callout_tests3" /><!--quickbook-escape-postfix--><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+
+</programlisting>
+ </para>
+ <para>
+ <calloutlist><callout arearefs="callout_tests3co" id="callout_tests3"><para>
+ </para>
+ <important>
+ <para>
+ test
+ </para>
+ </important>
+ <para>
+ </para></callout></calloutlist>
+ </para>
 </article>

Modified: trunk/tools/quickbook/test/callouts.quickbook
==============================================================================
--- trunk/tools/quickbook/test/callouts.quickbook (original)
+++ trunk/tools/quickbook/test/callouts.quickbook 2010-07-10 07:24:54 EDT (Sat, 10 Jul 2010)
@@ -15,3 +15,7 @@
 Example 3:
 
 [example3]
+
+Example 3 (again!):
+
+[example3]


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