|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70963 - in branches/quickbook-dev/tools/quickbook: src test test/doc-info
From: dnljms_at_[hidden]
Date: 2011-04-03 17:15:16
Author: danieljames
Date: 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
New Revision: 70963
URL: http://svn.boost.org/trac/boost/changeset/70963
Log:
Quickbook: Nested documents in 1.6.
If an included file has a docinfo block, use that docinfo. I'm not
entirely sure if the nested file be treated as if it's completely
standalone - i.e. should macros and templates defined in the parent be
used?
Also, there's some odd behaviour in quickbook if the docinfo block in an
included file has a parse error. It just goes back to the start and
parses as a file without a docinfo block. I think it would be better if
this was a hard error, but what should happen in someone has defined a
template with the same name as a docinfo block? That's actually valid in
existing quickbook, so the dodgy docinfo block might just be a template
call.
Text files modified:
branches/quickbook-dev/tools/quickbook/src/actions.cpp | 31 +++++++----------
branches/quickbook-dev/tools/quickbook/src/actions.hpp | 11 +++++-
branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 10 ++++-
branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 8 ++-
branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 68 +++++++++++++++++++++++++++------------
branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 22 ++++++++++--
branches/quickbook-dev/tools/quickbook/src/quickbook.hpp | 2
branches/quickbook-dev/tools/quickbook/test/doc-info/source-mode-1.6.gold | 27 ++++++++++-----
branches/quickbook-dev/tools/quickbook/test/include_1_6-2.gold | 4 ++
9 files changed, 122 insertions(+), 61 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-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -1136,16 +1136,6 @@
std::vector<template_body> const& args,
file_position pos)
{
- ++actions.template_depth;
- if (actions.template_depth > actions.max_template_depth)
- {
- detail::outerr(actions.filename, pos.line)
- << "Infinite loop detected" << std::endl;
- --actions.template_depth;
- ++actions.error_count;
- return;
- }
-
// The template arguments should have the scope that the template was
// called from, not the template's own scope.
//
@@ -1159,6 +1149,15 @@
{
template_state state(actions);
+ ++actions.template_depth;
+ if (actions.template_depth > actions.max_template_depth)
+ {
+ detail::outerr(actions.filename, pos.line)
+ << "Infinite loop detected" << std::endl;
+ ++actions.error_count;
+ return;
+ }
+
// Store the current section level so that we can ensure that
// [section] and [endsect] tags in the template are balanced.
actions.min_section_level = actions.section_level;
@@ -1179,7 +1178,6 @@
if (!get_arg_result)
{
- --actions.template_depth;
return;
}
///////////////////////////////////
@@ -1196,7 +1194,6 @@
<< detail::utf8(symbol->body.content.get_quickbook())
<< "------------------end--------------------" << std::endl
<< std::endl;
- --actions.template_depth;
++actions.error_count;
return;
}
@@ -1207,7 +1204,6 @@
<< "Mismatched sections in template "
<< detail::utf8(symbol->identifier)
<< std::endl;
- --actions.template_depth;
++actions.error_count;
return;
}
@@ -1224,7 +1220,6 @@
else {
actions.phrase << phrase;
}
- --actions.template_depth;
}
void call_code_snippet(quickbook::actions& actions,
@@ -1284,7 +1279,6 @@
<< "------------------end--------------------" << std::endl
;
++actions.error_count;
- --actions.template_depth;
return;
}
@@ -1297,8 +1291,6 @@
block += "</callout>";
}
block += "</calloutlist>";
-
- --actions.template_depth;
}
actions.out << block;
@@ -1780,6 +1772,9 @@
assert(load_type == block_tags::include ||
load_type == block_tags::import);
+ // Check this before qbk_version_n gets changed by the inner file.
+ bool keep_inner_source_mode = (qbk_version_n < 106);
+
{
file_state state(actions,
load_type == block_tags::import ? file_state::scope_none :
@@ -1811,7 +1806,7 @@
actions, true);
// Don't restore source_mode on older versions.
- if (qbk_version_n < 106) state.source_mode = actions.source_mode;
+ if (keep_inner_source_mode) state.source_mode = actions.source_mode;
}
// restore the __FILENAME__ macro
Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -337,8 +337,15 @@
quickbook::actions& actions;
};
- void pre(collector& out, quickbook::actions& actions, bool ignore_docinfo = false);
- void post(collector& out, quickbook::actions& actions, bool ignore_docinfo = false);
+ enum docinfo_types
+ {
+ docinfo_ignore = 0,
+ docinfo_main = 1,
+ docinfo_nested = 2
+ };
+
+ void pre(collector& out, quickbook::actions& actions, docinfo_types = docinfo_main);
+ void post(collector& out, quickbook::actions& actions, docinfo_types = docinfo_main);
struct phrase_to_docinfo_action_impl
{
Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -22,11 +22,9 @@
actions::actions(fs::path const& filein_, fs::path const& xinclude_base_, string_stream& out_)
: grammar_()
- , doc_type()
, doc_title_qbk()
, xinclude_base(xinclude_base_)
- , template_depth(0)
, templates()
, error_count(0)
, anchors()
@@ -34,6 +32,7 @@
, warned_about_breaks(false)
, context(0)
+ , doc_type()
, process_state(process_normal)
, macro()
, source_mode("c++")
@@ -41,6 +40,7 @@
, filename(filein_)
, filename_relative(filein_.filename())
+ , template_depth(0)
, section_level(0)
, min_section_level(0)
, section_id()
@@ -98,6 +98,8 @@
file_state::file_state(actions& a, scope_flags scope)
: a(a)
, scope(scope)
+ , qbk_version(qbk_version_n)
+ , doc_type(a.doc_type)
, doc_id(a.doc_id)
, filename(a.filename)
, filename_relative(a.filename_relative)
@@ -113,6 +115,8 @@
file_state::~file_state()
{
a.values.builder.restore();
+ boost::swap(qbk_version_n, qbk_version);
+ boost::swap(a.doc_type, doc_type);
boost::swap(a.doc_id, doc_id);
boost::swap(a.filename, filename);
boost::swap(a.filename_relative, filename_relative);
@@ -124,6 +128,7 @@
template_state::template_state(actions& a)
: file_state(a, file_state::scope_all)
+ , template_depth(a.template_depth)
, section_level(a.section_level)
, min_section_level(a.min_section_level)
, section_id(a.section_id)
@@ -137,6 +142,7 @@
{
a.phrase.pop();
a.out.pop();
+ boost::swap(a.template_depth, template_depth);
boost::swap(a.section_level, section_level);
boost::swap(a.min_section_level, min_section_level);
boost::swap(a.section_id, section_id);
Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -46,11 +46,8 @@
};
// global state
- std::string doc_type; // For the whole document, not
- // the current file.
std::string doc_title_qbk;
fs::path xinclude_base;
- int template_depth;
template_stack templates;
int error_count;
string_list anchors;
@@ -59,6 +56,7 @@
int context;
// state saved for files and templates.
+ std::string doc_type;
process_flags process_state;
string_symbols macro;
std::string source_mode;
@@ -69,6 +67,7 @@
// or include path).
// state saved for templates.
+ int template_depth;
int section_level;
int min_section_level;
std::string section_id;
@@ -136,6 +135,8 @@
quickbook::actions& a;
scope_flags scope;
+ unsigned qbk_version;
+ std::string doc_type;
std::string doc_id;
fs::path filename;
fs::path filename_relative;
@@ -152,6 +153,7 @@
explicit template_state(actions&);
~template_state();
+ int template_depth;
int section_level;
int min_section_level;
std::string section_id;
Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -68,7 +68,7 @@
return values;
}
- void pre(collector& out, quickbook::actions& actions, bool ignore_docinfo)
+ void pre(collector& out, quickbook::actions& actions, docinfo_types docinfo_type)
{
// The doc_info in the file has been parsed. Here's what we'll do
// *before* anything else.
@@ -91,6 +91,10 @@
doc_title = values.consume(doc_info_tags::title);
actions.doc_title_qbk = doc_title.get_quickbook();
}
+ else
+ {
+ actions.doc_type.clear();
+ }
std::vector<std::string> duplicates;
@@ -131,20 +135,20 @@
if (actions.doc_id.empty())
{
- assert(qbk_version_n < 106 || !ignore_docinfo);
+ assert(qbk_version_n < 106 || docinfo_type == docinfo_main);
actions.doc_id = detail::make_identifier(actions.doc_title_qbk);
}
// if we're ignoring the document info, we're done.
- if (ignore_docinfo)
+ if (!docinfo_type)
{
return;
}
// Make sure we really did have a document info block.
- assert(doc_title.check());
+ assert(doc_title.check() && !actions.doc_type.empty());
// Quickbook version
@@ -152,12 +156,23 @@
if (qbk_version.empty())
{
- // hard code quickbook version to v1.1
- qbk_major_version = 1;
- qbk_minor_version = 1;
- detail::outwarn(actions.filename,1)
- << "Warning: Quickbook version undefined. "
- "Version 1.1 is assumed" << std::endl;
+ // Always reset quickbook version if we're not ignoring the docinfo.
+ // This is so that the file is interpreted as if it was standalone.
+ if (docinfo_type)
+ {
+ // hard code quickbook version to v1.1
+ qbk_major_version = 1;
+ qbk_minor_version = 1;
+ qbk_version_n = 101;
+ detail::outwarn(actions.filename,1)
+ << "Warning: Quickbook version undefined. "
+ "Version 1.1 is assumed" << std::endl;
+ }
+ else
+ {
+ qbk_major_version = qbk_version_n / 100;
+ qbk_minor_version = qbk_version_n % 100;
+ }
}
else
{
@@ -165,10 +180,11 @@
qbk_major_version = qbk_version_values.consume().get_int();
qbk_minor_version = qbk_version_values.consume().get_int();
qbk_version_values.finish();
+
+ qbk_version_n = ((unsigned) qbk_major_version * 100) +
+ (unsigned) qbk_minor_version;
}
- qbk_version_n = ((unsigned) qbk_major_version * 100) +
- (unsigned) qbk_minor_version;
if (qbk_version_n == 106)
{
@@ -242,15 +258,21 @@
// Write out header
- out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- << "<!DOCTYPE "
- << actions.doc_type
- << " PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
- << " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">\n"
- << '<' << actions.doc_type << "\n"
+ if (docinfo_type == docinfo_main)
+ {
+ out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<!DOCTYPE "
+ << actions.doc_type
+ << " PUBLIC \"-//Boost//DTD BoostBook XML V1.0//EN\"\n"
+ << " \"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd\">\n"
+ ;
+ }
+
+ out << '<' << actions.doc_type << "\n"
<< " id=\""
<< actions.doc_id
- << "\"\n";
+ << "\"\n"
+ ;
if(!lang.empty())
{
@@ -406,13 +428,15 @@
}
}
- void post(collector& out, quickbook::actions& actions, bool ignore_docinfo)
+ void post(collector& out, quickbook::actions& actions, docinfo_types docinfo_type)
{
// if we're ignoring the document info, do nothing.
- if (ignore_docinfo)
+ if (!docinfo_type)
{
return;
- }
+ }
+
+ assert(!actions.doc_type.empty());
// We've finished generating our output. Here's what we'll do
// *after* everything else.
Modified: branches/quickbook-dev/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/quickbook.cpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -70,7 +70,7 @@
//
///////////////////////////////////////////////////////////////////////////
int
- parse_file(fs::path const& filein_, actions& actor, bool ignore_docinfo)
+ parse_file(fs::path const& filein_, actions& actor, bool nested_file)
{
using std::vector;
using std::string;
@@ -85,16 +85,30 @@
iterator first(storage.begin());
iterator last(storage.end());
+ // This is awkward. When not ignoring docinfo, the source_mode should be
+ // reset, but the code doesn't find out if the docinfo is ignored until
+ // too late. So reset it now, but save it in order to undo the reset if
+ // appopriate.
+ std::string saved_source_mode = actor.source_mode;
+ if (qbk_version_n >= 106) actor.source_mode = "c++";
+
cl::parse_info<iterator> info = cl::parse(first, last, actor.grammar().doc_info);
- if (info.hit || ignore_docinfo)
+ docinfo_types docinfo_type =
+ !nested_file ? docinfo_main :
+ info.hit && qbk_version_n >= 106 ? docinfo_nested :
+ docinfo_ignore;
+
+ if (!info.hit) actor.source_mode = saved_source_mode;
+
+ if (info.hit || !docinfo_type)
{
- pre(actor.out, actor, ignore_docinfo);
+ pre(actor.out, actor, docinfo_type);
info = cl::parse(info.hit ? info.stop : first, last, actor.grammar().block);
if (info.full)
{
- post(actor.out, actor, ignore_docinfo);
+ post(actor.out, actor, docinfo_type);
}
}
Modified: branches/quickbook-dev/tools/quickbook/src/quickbook.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/quickbook.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/quickbook.hpp 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -28,7 +28,7 @@
extern std::vector<fs::path> include_path;
extern std::vector<std::string> preset_defines;
- int parse_file(fs::path const& filein_, actions& actor, bool ignore_docinfo = false);
+ int parse_file(fs::path const& filein_, actions& actor, bool nested_file = false);
// Some initialisation methods
//
Modified: branches/quickbook-dev/tools/quickbook/test/doc-info/source-mode-1.6.gold
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/doc-info/source-mode-1.6.gold (original)
+++ branches/quickbook-dev/tools/quickbook/test/doc-info/source-mode-1.6.gold 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -18,26 +18,35 @@
<programlisting>This shouldn't be highlighted.</programlisting>
</para>
- <para>
-
+ <article id="c___test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>C++ source mode include</title>
+ <para>
+
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
- </para>
+ </para>
+ </article>
<para>
<programlisting>This shouldn't be highlighted.</programlisting>
</para>
- <para>
-
+ <article id="c___test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Python source mode include</title>
+ <para>
+
<programlisting><phrase role="keyword">def</phrase> <phrase role="identifier">foo</phrase><phrase role="special">():</phrase></programlisting>
- </para>
+ </para>
+ </article>
<para>
<programlisting>This shouldn't be highlighted.</programlisting>
</para>
- <para>
-
+ <article id="c___test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Teletype source mode include</title>
+ <para>
+
<programlisting>This shouldn't be highlighted</programlisting>
- </para>
+ </para>
+ </article>
<para>
<programlisting>This shouldn't be highlighted.</programlisting>
Modified: branches/quickbook-dev/tools/quickbook/test/include_1_6-2.gold
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/include_1_6-2.gold (original)
+++ branches/quickbook-dev/tools/quickbook/test/include_1_6-2.gold 2011-04-03 17:15:14 EDT (Sun, 03 Apr 2011)
@@ -3,6 +3,10 @@
<article id="include-test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Include Test</title>
+ <article id="include-sub" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Include Test Sub Document</title>
+ </article>
<section id="include-test.test">
<title><link linkend="include-test.test">Test</link></title>
<para>
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