diff --git a/src/actions.hpp b/src/actions.hpp index 82d841b..50ae3bc 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -302,8 +302,8 @@ namespace quickbook }; // Returns the doc_type, or an empty string if there isn't one. - std::string pre(collector& out, quickbook::actions& actions, value include_doc_id, bool nested_file); - void post(collector& out, quickbook::actions& actions, std::string const& doc_type); + std::string pre(quickbook::actions& actions, parse_iterator pos, value include_doc_id, bool nested_file); + void post(quickbook::actions& actions, std::string const& doc_type); struct to_value_scoped_action : scoped_action_base { diff --git a/src/doc_info_actions.cpp b/src/doc_info_actions.cpp index 19a9284..fa8f1c8 100644 --- a/src/doc_info_actions.cpp +++ b/src/doc_info_actions.cpp @@ -104,7 +104,7 @@ namespace quickbook if(result < 100 || result > 106) { - detail::outerr(actions.current_file->path, 1) + detail::outerr(actions.current_file->path) << "Unknown version: " << major_verison << "." @@ -118,7 +118,7 @@ namespace quickbook return result; } - std::string pre(collector& out, quickbook::actions& actions, + std::string pre(quickbook::actions& actions, parse_iterator pos, value include_doc_id, bool nested_file) { // The doc_info in the file has been parsed. Here's what we'll do @@ -136,6 +136,7 @@ namespace quickbook bool use_doc_info = false; std::string doc_type; value doc_title; + if (values.check(doc_info_tags::type)) { doc_type = values.consume(doc_info_tags::type).get_quickbook(); @@ -146,11 +147,18 @@ namespace quickbook { if (!nested_file) { - detail::outerr(actions.current_file->path, 1) + detail::outerr(actions.current_file, pos.base()) << "No doc_info block." << std::endl; ++actions.error_count; + + // Create a fake document info block in order to continue. + doc_type = "article"; + doc_title = qbk_value_ref(actions.current_file, + pos.base(), pos.base(), + doc_info_tags::type); + use_doc_info = true; } } @@ -177,7 +185,8 @@ namespace quickbook if(!duplicates.empty()) { - detail::outwarn(actions.current_file->path,1) + // TODO: This is the *end* of the document info. + detail::outwarn(actions.current_file, pos.base()) << (duplicates.size() > 1 ? "Duplicate attributes" : "Duplicate attribute") << ":" << detail::utf8(boost::algorithm::join(duplicates, ", ")) @@ -203,7 +212,7 @@ namespace quickbook if (new_version != qbk_version_n && new_version == 106) { - detail::outwarn(actions.current_file->path,1) + detail::outwarn(actions.current_file->path) << "Quickbook 1.6 is still under development and is " "likely to change in the future." << std::endl; } @@ -214,7 +223,7 @@ namespace quickbook else if (use_doc_info) { // hard code quickbook version to v1.1 qbk_version_n = 101; - detail::outwarn(actions.current_file->path,1) + detail::outwarn(actions.current_file, pos.base()) << "Quickbook version undefined. " "Version 1.1 is assumed" << std::endl; } @@ -277,7 +286,7 @@ namespace quickbook if(!invalid_attributes.empty()) { - detail::outwarn(actions.current_file->path,1) + detail::outwarn(actions.current_file->path) << (invalid_attributes.size() > 1 ? "Invalid attributes" : "Invalid attribute") << " for '" << detail::utf8(doc_type) << " document info': " @@ -291,7 +300,7 @@ namespace quickbook if (!nested_file) { - out << "\n" + actions.out << "\n" << "\n"; + actions.out << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n"; std::ostringstream tmp; @@ -486,13 +495,13 @@ namespace quickbook } if(doc_type != "library") { - write_document_title(out, doc_title, version); + write_document_title(actions.out, doc_title, version); } std::string docinfo = tmp.str(); if(!docinfo.empty()) { - out << " <" << doc_type << "info>\n" + actions.out << " <" << doc_type << "info>\n" << docinfo << " \n" << "\n" @@ -500,13 +509,13 @@ namespace quickbook } if(doc_type == "library") { - write_document_title(out, doc_title, version); + write_document_title(actions.out, doc_title, version); } return doc_type; } - - void post(collector& out, quickbook::actions& actions, std::string const& doc_type) + + void post(quickbook::actions& actions, std::string const& doc_type) { // We've finished generating our output. Here's what we'll do // *after* everything else. @@ -518,13 +527,13 @@ namespace quickbook << std::endl; while(actions.ids.section_level() > 1) { - out << ""; + actions.out << ""; actions.ids.end_section(); } } actions.ids.end_file(); - if (!doc_type.empty()) out << "\n\n\n"; + if (!doc_type.empty()) actions.out << "\n\n\n"; } static void write_document_title(collector& out, value const& title, value const& version) diff --git a/src/quickbook.cpp b/src/quickbook.cpp index 8fbc4e5..cc97636 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -78,13 +78,16 @@ namespace quickbook parse_iterator last(actor.current_file->source.end()); cl::parse_info info = cl::parse(first, last, actor.grammar().doc_info); + assert(info.hit); + if (!actor.error_count) { - std::string doc_type = pre(actor.out, actor, include_doc_id, nested_file); + parse_iterator pos = info.stop; + std::string doc_type = pre(actor, pos, include_doc_id, nested_file); info = cl::parse(info.hit ? info.stop : first, last, actor.grammar().block); - post(actor.out, actor, doc_type); + post(actor, doc_type); if (!info.full) { diff --git a/test/doc-info/Jamfile.v2 b/test/doc-info/Jamfile.v2 index be99ed8..f7d262c 100644 --- a/test/doc-info/Jamfile.v2 +++ b/test/doc-info/Jamfile.v2 @@ -30,4 +30,5 @@ test-suite quickbook.test : [ quickbook-test empty_title-1_1 ] [ quickbook-test empty_title-1_5 ] [ quickbook-test empty_title-1_6 ] + [ quickbook-error-test missing_doc_info-1_6-fail ] ; diff --git a/test/doc-info/missing_doc_info-1_6-fail.quickbook b/test/doc-info/missing_doc_info-1_6-fail.quickbook new file mode 100644 index 0000000..6f0b2cd --- /dev/null +++ b/test/doc-info/missing_doc_info-1_6-fail.quickbook @@ -0,0 +1,3 @@ +[quickbook 1.6] + +Hello!