|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75246 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-02 03:43:43
Author: danieljames
Date: 2011-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
New Revision: 75246
URL: http://svn.boost.org/trac/boost/changeset/75246
Log:
Quickbook: Move section_info into id_generator.
And shuffle things round a bit to avoid adding too many dependents to
id_generator. For 1.6 I want section_info to use id_generator to nest
ids properly when there are duplicate section ids.
Added:
branches/quickbook-dev/tools/quickbook/src/actions_state.hpp (contents, props changed)
Text files modified:
branches/quickbook-dev/tools/quickbook/src/actions.cpp | 41 +++++++++++++++---------------
branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 18 +++----------
branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 53 ---------------------------------------
branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 10 +++---
branches/quickbook-dev/tools/quickbook/src/fwd.hpp | 1
branches/quickbook-dev/tools/quickbook/src/id_generator.cpp | 13 +++++++++
branches/quickbook-dev/tools/quickbook/src/id_generator.hpp | 12 +++++++++
branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 12 ++++----
8 files changed, 63 insertions(+), 97 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 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -25,6 +25,7 @@
#include "utils.hpp"
#include "markups.hpp"
#include "actions_class.hpp"
+#include "actions_state.hpp"
#include "grammar.hpp"
#include "input_path.hpp"
#include "block_tags.hpp"
@@ -44,8 +45,8 @@
std::string const& section_id)
{
std::string id = actions.doc_id;
- if(!id.empty() && !actions.section.qualified_id.empty()) id += '.';
- id += actions.section.qualified_id;
+ if(!id.empty() && !actions.section->qualified_id.empty()) id += '.';
+ id += actions.section->qualified_id;
if(!id.empty() && !section_id.empty()) id += '.';
id += section_id;
return id;
@@ -348,7 +349,7 @@
if (generic)
{
- level = actions.section.level + 2;
+ level = actions.section->level + 2;
// section.level is zero-based. We need to use a
// one-based heading which is one greater
// than the current. Thus: section.level + 2.
@@ -365,7 +366,7 @@
if (!generic && qbk_version_n < 103) // version 1.2 and below
{
std::string anchor = actions.ids.add(
- actions.section.id + '.' +
+ actions.section->id + '.' +
detail::make_identifier(content.get_boostbook()),
id_generator::generated_heading);
@@ -1196,7 +1197,7 @@
// Store the current section level so that we can ensure that
// [section] and [endsect] tags in the template are balanced.
- actions.section.min_level = actions.section.level;
+ actions.section->min_level = actions.section->level;
// Quickbook 1.4-: When expanding the tempalte continue to use the
// current scope (the dynamic scope).
@@ -1234,7 +1235,7 @@
return;
}
- if (actions.section.level != actions.section.min_level)
+ if (actions.section->level != actions.section->min_level)
{
detail::outerr(actions.filename, pos.line)
<< "Mismatched sections in template "
@@ -1562,24 +1563,24 @@
value content = values.consume();
values.finish();
- actions.section.id = !element_id.empty() ?
+ actions.section->id = !element_id.empty() ?
element_id.get_quickbook() :
detail::make_identifier(content.get_quickbook());
- if (actions.section.level != 0)
- actions.section.qualified_id += '.';
+ if (actions.section->level != 0)
+ actions.section->qualified_id += '.';
else
- BOOST_ASSERT(actions.section.qualified_id.empty());
+ BOOST_ASSERT(actions.section->qualified_id.empty());
- actions.section.qualified_id += actions.section.id;
- ++actions.section.level;
+ actions.section->qualified_id += actions.section->id;
+ ++actions.section->level;
// TODO: This could be awkward if there's a clash, possibly
// needs another category, between explicit and generated.
std::string full_id = actions.ids.add(
qbk_version_n < 103 ?
- actions.doc_id + "." + actions.section.id :
- actions.doc_id + "." + actions.section.qualified_id,
+ actions.doc_id + "." + actions.section->id :
+ actions.doc_id + "." + actions.section->qualified_id,
!element_id.empty() ?
id_generator::explicit_id :
id_generator::generated_section);
@@ -1608,7 +1609,7 @@
{
write_anchors(actions, actions.out);
- if (actions.section.level <= actions.section.min_level)
+ if (actions.section->level <= actions.section->min_level)
{
detail::outerr(actions.filename, pos.line)
<< "Mismatched [endsect] near column " << pos.column << ".\n";
@@ -1617,18 +1618,18 @@
return;
}
- --actions.section.level;
+ --actions.section->level;
actions.out << "</section>";
- if (actions.section.level == 0)
+ if (actions.section->level == 0)
{
- actions.section.qualified_id.clear();
+ actions.section->qualified_id.clear();
}
else
{
std::string::size_type const n =
- actions.section.qualified_id.find_last_of('.');
- actions.section.qualified_id.erase(n, std::string::npos);
+ actions.section->qualified_id.find_last_of('.');
+ actions.section->qualified_id.erase(n, std::string::npos);
}
}
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-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -9,6 +9,7 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include "actions_class.hpp"
+#include "actions_state.hpp"
#include "quickbook.hpp"
#include "grammar.hpp"
#include "input_path.hpp"
@@ -44,7 +45,7 @@
, filename_relative(filein_.filename())
, template_depth(0)
- , section()
+ , section(0)
, out(out_)
, phrase()
@@ -134,24 +135,13 @@
template_state::template_state(actions& a)
: file_state(a, file_state::scope_all)
, template_depth(a.template_depth)
- , section(a.section)
+ , section(*a.section)
{
}
template_state::~template_state()
{
boost::swap(a.template_depth, template_depth);
- boost::swap(a.section, section);
- }
-
- section_info::section_info()
- : level(0), min_level(0), id(), qualified_id() {}
-
- void swap(section_info& a, section_info& b)
- {
- boost::swap(a.level, b.level);
- boost::swap(a.min_level, b.min_level);
- boost::swap(a.id, b.id);
- boost::swap(a.qualified_id, b.qualified_id);
+ boost::swap(*a.section, section);
}
}
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-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -21,17 +21,6 @@
namespace cl = boost::spirit::classic;
namespace fs = boost::filesystem;
- struct section_info
- {
- section_info();
-
- int level;
- int min_level;
- std::string id;
- std::string qualified_id;
- };
- void swap(section_info&, section_info&);
-
struct actions
{
actions(fs::path const& filein_, fs::path const& xinclude_base, string_stream& out_,
@@ -74,7 +63,7 @@
// state saved for templates.
int template_depth;
- section_info section;
+ section_info* section;
// output state - scoped by templates and grammar
collector out; // main output stream
@@ -117,46 +106,6 @@
element_id_warning_action element_id_warning;
};
-
- // State savers
-
- struct file_state
- {
- enum scope_flags {
- scope_none = 0,
- scope_macros = 1,
- scope_templates = 2,
- scope_output = 4,
- scope_callables = scope_macros + scope_templates,
- scope_all = scope_callables + scope_output
- };
-
- explicit file_state(actions&, scope_flags);
- ~file_state();
-
- quickbook::actions& a;
- scope_flags scope;
- unsigned qbk_version;
- bool imported;
- std::string doc_type;
- std::string doc_id;
- fs::path filename;
- fs::path filename_relative;
- std::string source_mode;
- string_symbols macro;
- private:
- file_state(file_state const&);
- file_state& operator=(file_state const&);
- };
-
- struct template_state : file_state
- {
- explicit template_state(actions&);
- ~template_state();
-
- int template_depth;
- section_info section;
- };
}
#endif // BOOST_SPIRIT_ACTIONS_CLASS_HPP
Added: branches/quickbook-dev/tools/quickbook/src/actions_state.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/src/actions_state.hpp 2011-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,61 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ 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_ACTIONS_STATE_HPP)
+#define BOOST_SPIRIT_ACTIONS_STATE_HPP
+
+#include "actions_class.hpp"
+#include "id_generator.hpp"
+
+namespace quickbook
+{
+ // State savers
+ //
+ // Defined in actions_class.cpp
+
+ struct file_state
+ {
+ enum scope_flags {
+ scope_none = 0,
+ scope_macros = 1,
+ scope_templates = 2,
+ scope_output = 4,
+ scope_callables = scope_macros + scope_templates,
+ scope_all = scope_callables + scope_output
+ };
+
+ explicit file_state(actions&, scope_flags);
+ ~file_state();
+
+ quickbook::actions& a;
+ scope_flags scope;
+ unsigned qbk_version;
+ bool imported;
+ std::string doc_type;
+ std::string doc_id;
+ fs::path filename;
+ fs::path filename_relative;
+ std::string source_mode;
+ string_symbols macro;
+ private:
+ file_state(file_state const&);
+ file_state& operator=(file_state const&);
+ };
+
+ struct template_state : file_state
+ {
+ explicit template_state(actions&);
+ ~template_state();
+
+ int template_depth;
+ section_info section;
+ };
+}
+
+#endif // BOOST_SPIRIT_ACTIONS_STATE_HPP
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-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -170,7 +170,7 @@
// Save the section level so it can be checked at the end of the
// document.
- actions.section.min_level = actions.section.level;
+ actions.section->min_level = actions.section->level;
// Quickbook version
@@ -465,17 +465,17 @@
assert(!actions.doc_type.empty());
// Close any open sections.
- if (actions.section.level > 0) {
+ if (actions.section->level > 0) {
detail::outwarn(actions.filename)
<< "Missing [endsect] detected at end of file."
<< std::endl;
- while(actions.section.level > 0) {
+ while(actions.section->level > 0) {
out << "</section>";
- --actions.section.level;
+ --actions.section->level;
}
- actions.section.qualified_id.clear();
+ actions.section->qualified_id.clear();
}
// We've finished generating our output. Here's what we'll do
Modified: branches/quickbook-dev/tools/quickbook/src/fwd.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/fwd.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/fwd.hpp 2011-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -19,6 +19,7 @@
struct quickbook_grammar;
struct collector;
struct id_generator;
+ struct section_info;
typedef position_iterator<std::string::const_iterator> iterator;
Modified: branches/quickbook-dev/tools/quickbook/src/id_generator.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_generator.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_generator.cpp 2011-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -452,4 +452,17 @@
result.append(copied, source.end());
return result;
}
+
+ // section_info
+
+ section_info::section_info()
+ : level(0), min_level(0), id(), qualified_id() {}
+
+ void swap(section_info& a, section_info& b)
+ {
+ boost::swap(a.level, b.level);
+ boost::swap(a.min_level, b.min_level);
+ boost::swap(a.id, b.id);
+ boost::swap(a.qualified_id, b.qualified_id);
+ }
}
Modified: branches/quickbook-dev/tools/quickbook/src/id_generator.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_generator.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_generator.hpp 2011-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -108,6 +108,18 @@
bool try_potential_id(placeholder_id*);
bool try_counted_id(placeholder_id*);
};
+
+ struct section_info
+ {
+ section_info();
+
+ int level;
+ int min_level;
+ std::string id;
+ std::string qualified_id;
+ };
+
+ void swap(section_info&, section_info&);
}
#endif
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-11-02 03:43:41 EDT (Wed, 02 Nov 2011)
@@ -73,9 +73,6 @@
void parse_file(fs::path const& filein_, actions& actor,
value include_doc_id, bool nested_file)
{
- using std::vector;
- using std::string;
-
std::string storage;
detail::load(filein_, storage); // Throws detail::load_error
@@ -98,9 +95,12 @@
if (!info.hit) actor.source_mode = saved_source_mode;
- section_info saved_section;
- if (docinfo_type == docinfo_nested)
+ section_info section;
+ section_info* saved_section = §ion;
+
+ if (docinfo_type) {
boost::swap(saved_section, actor.section);
+ }
if (info.hit || !docinfo_type)
{
@@ -113,7 +113,7 @@
}
}
- if (docinfo_type == docinfo_nested)
+ if (docinfo_type)
boost::swap(saved_section, actor.section);
if (!info.full)
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