Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75442 - in branches/quickbook-dev/tools/quickbook: doc src test/versions
From: dnljms_at_[hidden]
Date: 2011-11-10 13:15:50


Author: danieljames
Date: 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
New Revision: 75442
URL: http://svn.boost.org/trac/boost/changeset/75442

Log:
Quickbook: Support version info outside of document info blocks.
Text files modified:
   branches/quickbook-dev/tools/quickbook/doc/1_6.qbk | 13 ++++
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 126 ++++++++++++++++++++-------------------
   branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp | 67 ++++++++++++++------
   branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp | 8 +
   branches/quickbook-dev/tools/quickbook/src/id_manager.cpp | 3
   branches/quickbook-dev/tools/quickbook/src/id_manager.hpp | 1
   branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook | 3
   7 files changed, 132 insertions(+), 89 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/doc/1_6.qbk
==============================================================================
--- branches/quickbook-dev/tools/quickbook/doc/1_6.qbk (original)
+++ branches/quickbook-dev/tools/quickbook/doc/1_6.qbk 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -117,6 +117,19 @@
 
 [endsect] [/compatibility]
 
+[section:version Version info outside of document info block]
+
+Can now use `quickbook` and `compatibility-mode` tags at the beginning of the
+file. Either before or without a document info block. This is useful for
+files just containing templates, which don't really need a document info
+block.
+
+This change is also backdated to older versions. So when including from an
+older version, the included file's version can be set (older versions
+ignore document info in included files).
+
+[endsect]
+
 [section:heading_ids Explicit Heading Ids]
 
 Headings can now be given explicit ids:

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-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -78,6 +78,39 @@
         return values;
     }
 
+ unsigned get_version(quickbook::actions& actions, bool using_docinfo,
+ value version)
+ {
+ unsigned result = 0;
+
+ if (!version.empty()) {
+ value_consumer version_values(version);
+ bool before_docinfo = version_values.optional_consume(
+ doc_info_tags::before_docinfo).check();
+ int major_verison = version_values.consume().get_int();
+ int minor_verison = version_values.consume().get_int();
+ version_values.finish();
+
+ if (before_docinfo || using_docinfo) {
+ result = ((unsigned) major_verison * 100) +
+ (unsigned) minor_verison;
+
+ if(result < 100 || result > 106)
+ {
+ detail::outerr(actions.current_file->path, 1)
+ << "Unknown version: "
+ << major_verison
+ << "."
+ << minor_verison
+ << std::endl;
+ ++actions.error_count;
+ }
+ }
+ }
+
+ return result;
+ }
+
     void pre(collector& out, quickbook::actions& actions,
             value include_doc_id, docinfo_types docinfo_type)
     {
@@ -94,7 +127,7 @@
         while (values.check(value::default_tag)) values.consume();
                 
         value doc_title;
- if (values.check())
+ if (values.check(doc_info_tags::type))
         {
             actions.doc_type = values.consume(doc_info_tags::type).get_quickbook();
             doc_title = values.consume(doc_info_tags::title);
@@ -107,7 +140,9 @@
 
         std::vector<std::string> duplicates;
 
- value qbk_version = consume_list(values, doc_info_attributes::qbk_version, &duplicates);
+ value qbk_version = consume_list(values, doc_attributes::qbk_version, &duplicates);
+ value compatibility_mode = consume_list(values, doc_attributes::compatibility_mode, &duplicates);
+
         value id = consume_value_in_list(values, doc_info_attributes::id, &duplicates);
         value dirname = consume_value_in_list(values, doc_info_attributes::dirname, &duplicates);
         value last_revision = consume_value_in_list(values, doc_info_attributes::last_revision, &duplicates);
@@ -119,7 +154,6 @@
         std::vector<value> copyrights = consume_multiple_lists(values, doc_info_attributes::copyright);
         value license = consume_value_in_list(values, doc_info_attributes::license, &duplicates);
         std::vector<value> biblioids = consume_multiple_lists(values, doc_info_attributes::biblioid);
- value compatibility_mode = consume_list(values, doc_info_attributes::compatibility_mode, &duplicates);
         value xmlbase = consume_value_in_list(values, doc_info_attributes::xmlbase, &duplicates);
         
         // Skip over source-mode tags (already dealt with)
@@ -150,85 +184,53 @@
                 id.get_quickbook().begin(),
                 id.get_quickbook().end());
 
+ // Quickbook version
+
+ unsigned new_version = get_version(actions, docinfo_type, qbk_version);
+ if (new_version != qbk_version_n && new_version == 106)
+ {
+ detail::outwarn(actions.current_file->path,1)
+ << "Quickbook 1.6 is still under development and is "
+ "likely to change in the future." << std::endl;
+ }
+
+ unsigned compatibility_version =
+ get_version(actions, docinfo_type, compatibility_mode);
+
         // if we're ignoring the document info, just start the file
         // and we're done.
 
         if (!docinfo_type)
         {
+ if (new_version) qbk_version_n = new_version;
             actions.current_file_tmp->version(qbk_version_n);
- actions.ids.start_file(include_doc_id_, id_, actions.doc_title_qbk);
+
+ if (!compatibility_version)
+ compatibility_version = actions.ids.compatibility_version();
+
+ actions.ids.start_file(compatibility_version, include_doc_id_, id_,
+ actions.doc_title_qbk);
 
             return;
         }
 
- // Quickbook version
-
- int qbk_major_version, qbk_minor_version;
- unsigned compatibility_version;
+ // Otherwise we're starting a new (possiblity nested) document.
+ // So need to set the defaults.
 
- if (qbk_version.empty())
- {
+ if (new_version) {
+ qbk_version_n = new_version;
+ }
+ else {
             // hard code quickbook version to v1.1
- qbk_major_version = 1;
- qbk_minor_version = 1;
             qbk_version_n = 101;
             detail::outwarn(actions.current_file->path,1)
                 << "Quickbook version undefined. "
                 "Version 1.1 is assumed" << std::endl;
         }
- else
- {
- value_consumer qbk_version_values(qbk_version);
- 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;
- }
-
- if (qbk_version_n == 106)
- {
- detail::outwarn(actions.current_file->path,1)
- << "Quickbook 1.6 is still under development and is "
- "likely to change in the future." << std::endl;
- }
- else if(qbk_version_n < 100 || qbk_version_n > 106)
- {
- detail::outerr(actions.current_file->path,1)
- << "Unknown version of quickbook: quickbook "
- << qbk_major_version
- << "."
- << qbk_minor_version
- << std::endl;
- ++actions.error_count;
- }
-
- if (compatibility_mode.empty())
- {
+ if (!compatibility_version) {
             compatibility_version = qbk_version_n;
         }
- else
- {
- value_consumer values(compatibility_mode);
- int compatibility_major_version = values.consume().get_int();
- int compatibility_minor_version = values.consume().get_int();
- values.finish();
-
- compatibility_version = ((unsigned) compatibility_major_version * 100) +
- (unsigned) compatibility_minor_version;
-
- if (compatibility_version < 100 || compatibility_version > 106)
- {
- detail::outerr(actions.current_file->path,1)
- << "Unknown compatibility version of quickbook: "
- << qbk_major_version
- << "."
- << qbk_minor_version
- << std::endl;
- ++actions.error_count;
- }
- }
 
         actions.current_file_tmp->version(qbk_version_n);
 

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -74,6 +74,7 @@
                         quickbook_version, char_;
         cl::uint_parser<int, 10, 4, 4> doc_copyright_year;
         cl::symbols<> doc_types;
+ cl::symbols<value::tag_type> doc_info_attributes;
         cl::symbols<value::tag_type> doc_attributes;
         std::map<value::tag_type, cl::rule<scanner>* > attribute_rules;
         value::tag_type attribute_tag;
@@ -100,23 +101,41 @@
           , "reference", "set"
         ;
 
+ BOOST_FOREACH(value::tag_type t, doc_attributes::tags()) {
+ local.doc_attributes.add(doc_attributes::name(t), t);
+ local.doc_info_attributes.add(doc_attributes::name(t), t);
+ }
+
         BOOST_FOREACH(value::tag_type t, doc_info_attributes::tags()) {
- local.doc_attributes.add(doc_info_attributes::name(t), t);
+ local.doc_info_attributes.add(doc_info_attributes::name(t), t);
         }
         
         doc_info_details =
- space
- >> '[' >> space
- >> (local.doc_types >> cl::eps_p)
+ space
+ >> *( '['
+ >> space
+ >> local.doc_attributes [local.assign_attribute]
+ >> hard_space
+ >> actions.values.list(ph::var(local.attribute_tag))
+ [ cl::eps_p [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::before_docinfo)]
+ >> local.attribute_rule
+ ]
+ >> space
+ >> ']'
+ >> space
+ )
+ >> '['
+ >> space
+ >> (local.doc_types >> cl::eps_p)
                                             [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::type)]
- >> hard_space
+ >> hard_space
>> actions.to_value(doc_info_tags::title)
                 [ *(~cl::eps_p(cl::ch_p('[') | ']' | cl::eol_p) >> local.char_) ]
>> *(
                     space
>> '['
>> space
- >> ( local.doc_attributes
+ >> ( local.doc_info_attributes
                                             [local.assign_attribute]
                     | (+(cl::alnum_p | '_' | '-'))
                                             [local.fallback_attribute]
@@ -137,6 +156,26 @@
         // TODO: Clear phrase afterwards?
         local.doc_fallback = (*(~cl::eps_p(']') >> local.char_));
 
+ // Document Attributes
+
+ local.quickbook_version =
+ cl::uint_p [actions.values.entry(ph::arg1)]
+ >> '.'
+ >> uint2_t() [actions.values.entry(ph::arg1)]
+ ;
+
+ local.attribute_rules[doc_attributes::qbk_version] = &local.quickbook_version;
+
+ local.doc_compatibility_mode =
+ cl::uint_p [actions.values.entry(ph::arg1)]
+ >> '.'
+ >> uint2_t() [actions.values.entry(ph::arg1)]
+ ;
+
+ local.attribute_rules[doc_attributes::compatibility_mode] = &local.doc_compatibility_mode;
+
+ // Document Info Attributes
+
         // TODO: Restrictions on doc_id and doc_dirname?
 
         local.doc_simple = actions.to_value() [*(~cl::eps_p(']') >> local.char_)];
@@ -148,14 +187,6 @@
         local.attribute_rules[doc_info_attributes::lang] = &local.doc_simple;
         local.attribute_rules[doc_info_attributes::xmlbase] = &local.doc_simple;
 
- local.quickbook_version =
- cl::uint_p [actions.values.entry(ph::arg1)]
- >> '.'
- >> uint2_t() [actions.values.entry(ph::arg1)]
- ;
-
- local.attribute_rules[doc_info_attributes::qbk_version] = &local.quickbook_version;
-
         local.doc_copyright_holder
             = *( ~cl::eps_p
                     ( ']'
@@ -227,14 +258,6 @@
             ;
 
         local.attribute_rules[doc_info_attributes::biblioid] = &local.doc_biblioid;
-
- local.doc_compatibility_mode =
- cl::uint_p [actions.values.entry(ph::arg1)]
- >> '.'
- >> uint2_t() [actions.values.entry(ph::arg1)]
- ;
-
- local.attribute_rules[doc_info_attributes::compatibility_mode] = &local.doc_compatibility_mode;
 
         local.char_ = escape | cl::anychar_p[actions.plain_char];
     }

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -14,6 +14,7 @@
 namespace quickbook
 {
     QUICKBOOK_VALUE_TAGS(doc_info_tags, 0x400,
+ (before_docinfo)
         (type)
         (title)
         (author_surname)(author_first)
@@ -22,8 +23,12 @@
         (biblioid_class)(biblioid_value)
     )
 
- QUICKBOOK_VALUE_NAMED_TAGS(doc_info_attributes, 0x450,
+ QUICKBOOK_VALUE_NAMED_TAGS(doc_attributes, 0x440,
         ((qbk_version)("quickbook"))
+ ((compatibility_mode)("compatibility-mode"))
+ )
+
+ QUICKBOOK_VALUE_NAMED_TAGS(doc_info_attributes, 0x450,
         ((id)("id"))
         ((dirname)("dirname"))
         ((last_revision)("last-revision"))
@@ -35,7 +40,6 @@
         ((copyright)("copyright"))
         ((license)("license"))
         ((biblioid)("biblioid"))
- ((compatibility_mode)("compatibility-mode"))
         ((xmlbase)("xmlbase"))
         // Source mode must come last.
         ((source_mode)("source-mode"))

Modified: branches/quickbook-dev/tools/quickbook/src/id_manager.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_manager.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_manager.cpp 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -201,12 +201,13 @@
     id_manager::~id_manager() {}
 
     void id_manager::start_file(
+ unsigned compatibility_version,
             std::string const& include_doc_id,
             std::string const& id,
             std::string const& title)
     {
         boost::scoped_ptr<section_manager> new_section(
- current_section->start_file(false, current_section->compatibility_version,
+ current_section->start_file(false, compatibility_version,
                 include_doc_id, id, title, 0, 0));
 
         if (new_section) {

Modified: branches/quickbook-dev/tools/quickbook/src/id_manager.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/id_manager.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/id_manager.hpp 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -62,6 +62,7 @@
                 std::string const& title);
 
         void start_file(
+ unsigned compatibility_version,
                 std::string const& include_doc_id,
                 std::string const& id,
                 std::string const& title);

Modified: branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook (original)
+++ branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook 2011-11-10 13:15:49 EST (Thu, 10 Nov 2011)
@@ -1,6 +1,5 @@
-[article Mixed version tests
 [quickbook 1.6]
-]
+[article Mixed version tests]
 
 [import templates-1_1.qbk]
 [import templates-1_4.qbk]


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