2008-09-04 02:20:39 +04:00
|
|
|
#pragma once
|
|
|
|
|
2009-07-27 06:56:18 +04:00
|
|
|
#include "mark.h"
|
2008-09-04 02:20:39 +04:00
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
2009-07-10 08:17:30 +04:00
|
|
|
#include <sstream>
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
namespace YAML
|
|
|
|
{
|
|
|
|
// error messages
|
|
|
|
namespace ErrorMsg
|
|
|
|
{
|
2009-05-23 01:52:31 +04:00
|
|
|
const std::string YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument";
|
|
|
|
const std::string YAML_VERSION = "bad YAML version: ";
|
|
|
|
const std::string YAML_MAJOR_VERSION = "YAML major version too large";
|
|
|
|
const std::string TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments";
|
|
|
|
const std::string END_OF_MAP = "end of map not found";
|
|
|
|
const std::string END_OF_MAP_FLOW = "end of map flow not found";
|
|
|
|
const std::string END_OF_SEQ = "end of sequence not found";
|
|
|
|
const std::string END_OF_SEQ_FLOW = "end of sequence flow not found";
|
|
|
|
const std::string MULTIPLE_TAGS = "cannot assign multiple tags to the same node";
|
|
|
|
const std::string MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node";
|
|
|
|
const std::string MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node";
|
|
|
|
const std::string ALIAS_CONTENT = "aliases can't have any content, *including* tags";
|
|
|
|
const std::string INVALID_HEX = "bad character found while scanning hex number";
|
|
|
|
const std::string INVALID_UNICODE = "invalid unicode: ";
|
|
|
|
const std::string INVALID_ESCAPE = "unknown escape character: ";
|
|
|
|
const std::string UNKNOWN_TOKEN = "unknown token";
|
|
|
|
const std::string DOC_IN_SCALAR = "illegal document indicator in scalar";
|
|
|
|
const std::string EOF_IN_SCALAR = "illegal EOF in scalar";
|
|
|
|
const std::string CHAR_IN_SCALAR = "illegal character in scalar";
|
|
|
|
const std::string TAB_IN_INDENTATION = "illegal tab when looking for indentation";
|
|
|
|
const std::string FLOW_END = "illegal flow end";
|
|
|
|
const std::string BLOCK_ENTRY = "illegal block entry";
|
|
|
|
const std::string MAP_KEY = "illegal map key";
|
|
|
|
const std::string MAP_VALUE = "illegal map value";
|
|
|
|
const std::string ALIAS_NOT_FOUND = "alias not found after *";
|
|
|
|
const std::string ANCHOR_NOT_FOUND = "anchor not found after &";
|
|
|
|
const std::string CHAR_IN_ALIAS = "illegal character found while scanning alias";
|
|
|
|
const std::string CHAR_IN_ANCHOR = "illegal character found while scanning anchor";
|
|
|
|
const std::string ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar";
|
|
|
|
const std::string CHAR_IN_BLOCK = "unexpected character in block scalar";
|
2009-05-23 01:48:05 +04:00
|
|
|
const std::string AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes";
|
|
|
|
const std::string UNKNOWN_ANCHOR = "the referenced anchor is not defined";
|
2008-11-18 07:20:07 +03:00
|
|
|
|
2009-05-23 01:52:31 +04:00
|
|
|
const std::string INVALID_SCALAR = "invalid scalar";
|
|
|
|
const std::string KEY_NOT_FOUND = "key not found";
|
|
|
|
const std::string BAD_DEREFERENCE = "bad dereference";
|
|
|
|
|
|
|
|
const std::string UNMATCHED_GROUP_TAG = "unmatched group tag";
|
|
|
|
const std::string UNEXPECTED_END_SEQ = "unexpected end sequence token";
|
|
|
|
const std::string UNEXPECTED_END_MAP = "unexpected end map token";
|
|
|
|
const std::string SINGLE_QUOTED_CHAR = "invalid character in single-quoted string";
|
|
|
|
const std::string INVALID_ANCHOR = "invalid anchor";
|
|
|
|
const std::string INVALID_ALIAS = "invalid alias";
|
|
|
|
const std::string EXPECTED_KEY_TOKEN = "expected key token";
|
|
|
|
const std::string EXPECTED_VALUE_TOKEN = "expected value token";
|
|
|
|
const std::string UNEXPECTED_KEY_TOKEN = "unexpected key token";
|
|
|
|
const std::string UNEXPECTED_VALUE_TOKEN = "unexpected value token";
|
2008-09-04 02:20:39 +04:00
|
|
|
}
|
2008-11-18 07:20:07 +03:00
|
|
|
|
|
|
|
class Exception: public std::exception {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
Exception(const Mark& mark_, const std::string& msg_)
|
|
|
|
: mark(mark_), msg(msg_) {
|
2009-07-26 05:37:21 +04:00
|
|
|
std::stringstream output;
|
2009-07-27 06:56:18 +04:00
|
|
|
output << "Error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
|
2009-07-26 05:37:21 +04:00
|
|
|
what_ = output.str();
|
|
|
|
}
|
2009-01-02 02:59:37 +03:00
|
|
|
virtual ~Exception() throw() {}
|
2009-07-26 05:37:21 +04:00
|
|
|
virtual const char *what() const throw() { return what_.c_str(); }
|
2008-11-18 07:20:07 +03:00
|
|
|
|
2009-07-27 06:56:18 +04:00
|
|
|
Mark mark;
|
2008-11-18 07:20:07 +03:00
|
|
|
std::string msg;
|
2009-07-26 05:37:21 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string what_;
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParserException: public Exception {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
ParserException(const Mark& mark_, const std::string& msg_)
|
|
|
|
: Exception(mark_, msg_) {}
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class RepresentationException: public Exception {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
RepresentationException(const Mark& mark_, const std::string& msg_)
|
|
|
|
: Exception(mark_, msg_) {}
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// representation exceptions
|
|
|
|
class InvalidScalar: public RepresentationException {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
InvalidScalar(const Mark& mark_)
|
|
|
|
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class KeyNotFound: public RepresentationException {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
KeyNotFound(const Mark& mark_)
|
|
|
|
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND) {}
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
|
|
|
|
2009-01-01 05:40:18 +03:00
|
|
|
template <typename T>
|
|
|
|
class TypedKeyNotFound: public KeyNotFound {
|
|
|
|
public:
|
2009-07-27 06:56:18 +04:00
|
|
|
TypedKeyNotFound(const Mark& mark_, const T& key_)
|
|
|
|
: KeyNotFound(mark_), key(key_) {}
|
2009-01-02 02:59:37 +03:00
|
|
|
~TypedKeyNotFound() throw() {}
|
2009-01-01 05:40:18 +03:00
|
|
|
|
|
|
|
T key;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2009-07-27 06:56:18 +04:00
|
|
|
TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
|
|
|
|
return TypedKeyNotFound <T> (mark, key);
|
2009-01-01 05:40:18 +03:00
|
|
|
}
|
|
|
|
|
2008-11-18 07:20:07 +03:00
|
|
|
class BadDereference: public RepresentationException {
|
|
|
|
public:
|
|
|
|
BadDereference()
|
2009-07-27 06:56:18 +04:00
|
|
|
: RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
|
2008-11-18 07:20:07 +03:00
|
|
|
};
|
2009-05-23 01:52:31 +04:00
|
|
|
|
|
|
|
class EmitterException: public Exception {
|
|
|
|
public:
|
|
|
|
EmitterException(const std::string& msg_)
|
2009-07-27 06:56:18 +04:00
|
|
|
: Exception(Mark::null(), msg_) {}
|
2009-05-23 01:52:31 +04:00
|
|
|
};
|
2008-09-04 02:20:39 +04:00
|
|
|
}
|