|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70978 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-04-04 18:11:10
Author: danieljames
Date: 2011-04-04 18:11:09 EDT (Mon, 04 Apr 2011)
New Revision: 70978
URL: http://svn.boost.org/trac/boost/changeset/70978
Log:
Quickbook: Better error messages when loading a file.
Text files modified:
branches/quickbook-dev/tools/quickbook/src/actions.cpp | 47 +++++++++++++++++++++++++--------------
branches/quickbook-dev/tools/quickbook/src/actions.hpp | 1
branches/quickbook-dev/tools/quickbook/src/code_snippet.cpp | 4 --
branches/quickbook-dev/tools/quickbook/src/quickbook.cpp | 39 +++++++++++++++++----------------
branches/quickbook-dev/tools/quickbook/src/quickbook.hpp | 3 +
branches/quickbook-dev/tools/quickbook/src/utils.cpp | 34 +++++++---------------------
branches/quickbook-dev/tools/quickbook/src/utils.hpp | 9 ++++++
7 files changed, 71 insertions(+), 66 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-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -1839,6 +1839,7 @@
std::string ext = paths.filename.extension().generic_string();
std::vector<template_symbol> storage;
+ // Throws detail::load_error
actions.error_count +=
load_snippets(paths.filename, storage, ext, load_type);
@@ -1875,29 +1876,41 @@
check_path(values.consume(), actions), actions);
values.finish();
- if (qbk_version_n >= 106)
- {
- std::string ext = paths.filename.extension().generic_string();
-
- if (ext == ".qbk" || ext == ".quickbook")
+ try {
+ if (qbk_version_n >= 106)
{
- load_quickbook(actions, paths, include.get_tag(), include_doc_id);
+ std::string ext = paths.filename.extension().generic_string();
+
+ if (ext == ".qbk" || ext == ".quickbook")
+ {
+ load_quickbook(actions, paths, include.get_tag(), include_doc_id);
+ }
+ else
+ {
+ load_source_file(actions, paths, include.get_tag(), pos, include_doc_id);
+ }
}
else
{
- load_source_file(actions, paths, include.get_tag(), pos, include_doc_id);
+ if (include.get_tag() == block_tags::include)
+ {
+ load_quickbook(actions, paths, include.get_tag(), include_doc_id);
+ }
+ else
+ {
+ load_source_file(actions, paths, include.get_tag(), pos, include_doc_id);
+ }
}
}
- else
- {
- if (include.get_tag() == block_tags::include)
- {
- load_quickbook(actions, paths, include.get_tag(), include_doc_id);
- }
- else
- {
- load_source_file(actions, paths, include.get_tag(), pos, include_doc_id);
- }
+ catch (detail::load_error& e) {
+ ++actions.error_count;
+
+ detail::outerr(actions.filename, pos.line)
+ << "Loading file:"
+ << paths.filename
+ << ": "
+ << detail::utf8(e.what())
+ << std::endl;
}
}
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-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -52,6 +52,7 @@
return quickbook_range(0, max_);
}
+ // Throws detail::load_error
int load_snippets(fs::path const& file, std::vector<template_symbol>& storage,
std::string const& extension, value::tag_type load_type);
Modified: branches/quickbook-dev/tools/quickbook/src/code_snippet.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/code_snippet.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/code_snippet.cpp 2011-04-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -320,9 +320,7 @@
load_type == block_tags::import);
std::string code;
- int err = detail::load(file, code);
- if (err != 0)
- return err; // return early on error
+ detail::load(file, code); // Throws detail::load_error.
iterator first(code.begin());
iterator last(code.end());
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-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -69,18 +69,13 @@
// Parse a file
//
///////////////////////////////////////////////////////////////////////////
- int
- parse_file(fs::path const& filein_, actions& actor, bool nested_file)
+ int parse_file(fs::path const& filein_, actions& actor, bool nested_file)
{
using std::vector;
using std::string;
std::string storage;
- int err = detail::load(filein_, storage);
- if (err != 0) {
- ++actor.error_count;
- return err;
- }
+ detail::load(filein_, storage); // Throws detail::load_error
iterator first(storage.begin());
iterator last(storage.end());
@@ -119,8 +114,6 @@
<< "Syntax Error near column " << pos.column << ".\n";
++actor.error_count;
}
-
- return actor.error_count ? 1 : 0;
}
static int
@@ -132,19 +125,27 @@
actions actor(filein_, xinclude_base, out);
set_macros(actor);
- bool r = parse_file(filein_, actor);
- if (actor.section_level != 0)
- detail::outwarn(filein_)
- << "Warning missing [endsect] detected at end of file."
- << std::endl;
+
+ try {
+ parse_file(filein_, actor);
- if(actor.error_count)
- {
- detail::outerr()
- << "Error count: " << actor.error_count << ".\n";
+ if (actor.section_level != 0) {
+ detail::outwarn(filein_)
+ << "Warning missing [endsect] detected at end of file."
+ << std::endl;
+ }
+
+ if(actor.error_count) {
+ detail::outerr()
+ << "Error count: " << actor.error_count << ".\n";
+ }
+ }
+ catch (detail::load_error& e) {
+ ++actor.error_count;
+ detail::outerr(filein_) << detail::utf8(e.what()) << std::endl;
}
- return r;
+ return !!actor.error_count;
}
static int
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-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -28,7 +28,8 @@
extern std::vector<fs::path> include_path;
extern std::vector<std::string> preset_defines;
- int parse_file(fs::path const& filein_, actions& actor, bool nested_file = false);
+ int parse_file(fs::path const& filein_, actions& actor,
+ bool nested_file = false);
// Some initialisation methods
//
Modified: branches/quickbook-dev/tools/quickbook/src/utils.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/utils.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/utils.cpp 2011-04-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -8,7 +8,6 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include "utils.hpp"
-#include "input_path.hpp"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/filesystem/v3/fstream.hpp>
@@ -190,18 +189,14 @@
// newlines.
template <class InputIterator, class OutputIterator>
- bool normalize(InputIterator begin, InputIterator end,
- OutputIterator out, fs::path const& filename)
+ void normalize(InputIterator begin, InputIterator end,
+ OutputIterator out)
{
std::string encoding = read_bom(begin, end, out);
- if(encoding != "UTF-8" && encoding != "") {
- outerr(filename) << encoding.c_str()
- << " is not supported. Please use UTF-8."
- << std::endl;
-
- return false;
- }
+ if(encoding != "UTF-8" && encoding != "")
+ throw load_error(encoding +
+ " is not supported. Please use UTF-8.");
while(begin != end) {
if(*begin == '\r') {
@@ -213,11 +208,9 @@
*out++ = *begin++;
}
}
-
- return true;
}
- int load(fs::path const& filename, std::string& storage)
+ void load(fs::path const& filename, std::string& storage)
{
using std::endl;
using std::ios;
@@ -227,24 +220,15 @@
fs::ifstream in(filename, std::ios_base::in);
if (!in)
- {
- outerr(filename) << "Could not open input file." << endl;
- return 1;
- }
+ throw load_error("Could not open input file.");
// Turn off white space skipping on the stream
in.unsetf(ios::skipws);
- if(!normalize(
+ normalize(
istream_iterator<char>(in),
istream_iterator<char>(),
- std::back_inserter(storage),
- filename))
- {
- return 1;
- }
-
- return 0;
+ std::back_inserter(storage));
}
file_type get_file_type(std::string const& extension)
Modified: branches/quickbook-dev/tools/quickbook/src/utils.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/utils.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/utils.hpp 2011-04-04 18:11:09 EDT (Mon, 04 Apr 2011)
@@ -45,8 +45,15 @@
void unindent(std::string& program);
std::string escape_uri(std::string uri);
+
+ class load_error : public std::runtime_error
+ {
+ public:
+ explicit load_error(std::string const& arg)
+ : std::runtime_error(arg) {}
+ };
- int load(fs::path const& filename, std::string& storage);
+ void load(fs::path const& filename, std::string& storage);
// given a file extension, return the type of the source file
// we'll have an internal database for known file types.
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