Collected pos, line, and column into a Mark struct

This commit is contained in:
Jesse Beder
2009-07-27 02:56:18 +00:00
parent 9b78bd459b
commit b1ce042535
17 changed files with 145 additions and 137 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include "mark.h"
#include <exception>
#include <string>
#include <sstream>
@@ -60,16 +61,16 @@ namespace YAML
class Exception: public std::exception {
public:
Exception(int line_, int column_, const std::string& msg_)
: line(line_), column(column_), msg(msg_) {
Exception(const Mark& mark_, const std::string& msg_)
: mark(mark_), msg(msg_) {
std::stringstream output;
output << "Error at line " << line+1 << ", column " << column+1 << ": " << msg;
output << "Error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
what_ = output.str();
}
virtual ~Exception() throw() {}
virtual const char *what() const throw() { return what_.c_str(); }
int line, column;
Mark mark;
std::string msg;
private:
@@ -78,53 +79,53 @@ namespace YAML
class ParserException: public Exception {
public:
ParserException(int line_, int column_, const std::string& msg_)
: Exception(line_, column_, msg_) {}
ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
class RepresentationException: public Exception {
public:
RepresentationException(int line_, int column_, const std::string& msg_)
: Exception(line_, column_, msg_) {}
RepresentationException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
};
// representation exceptions
class InvalidScalar: public RepresentationException {
public:
InvalidScalar(int line_, int column_)
: RepresentationException(line_, column_, ErrorMsg::INVALID_SCALAR) {}
InvalidScalar(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
};
class KeyNotFound: public RepresentationException {
public:
KeyNotFound(int line_, int column_)
: RepresentationException(line_, column_, ErrorMsg::KEY_NOT_FOUND) {}
KeyNotFound(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND) {}
};
template <typename T>
class TypedKeyNotFound: public KeyNotFound {
public:
TypedKeyNotFound(int line_, int column_, const T& key_)
: KeyNotFound(line_, column_), key(key_) {}
TypedKeyNotFound(const Mark& mark_, const T& key_)
: KeyNotFound(mark_), key(key_) {}
~TypedKeyNotFound() throw() {}
T key;
};
template <typename T>
TypedKeyNotFound <T> MakeTypedKeyNotFound(int line, int column, const T& key) {
return TypedKeyNotFound <T> (line, column, key);
TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
return TypedKeyNotFound <T> (mark, key);
}
class BadDereference: public RepresentationException {
public:
BadDereference()
: RepresentationException(-1, -1, ErrorMsg::BAD_DEREFERENCE) {}
: RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
};
class EmitterException: public Exception {
public:
EmitterException(const std::string& msg_)
: Exception(-1, -1, msg_) {}
: Exception(Mark::null(), msg_) {}
};
}

View File

@@ -1,14 +1,15 @@
#pragma once
#include "conversion.h"
#include "exceptions.h"
#include "iterator.h"
#include "mark.h"
#include "noncopyable.h"
#include "parserstate.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include "parserstate.h"
#include "exceptions.h"
#include "iterator.h"
#include "conversion.h"
#include "noncopyable.h"
#include <iostream>
namespace YAML
{
@@ -30,8 +31,7 @@ namespace YAML
CONTENT_TYPE GetType() const;
// file location of start of this node
int GetLine() const { return m_line; }
int GetColumn() const { return m_column; }
const Mark GetMark() const { return m_mark; }
// accessors
Iterator begin() const;
@@ -85,7 +85,7 @@ namespace YAML
void ParseAlias(Scanner *pScanner, const ParserState& state);
private:
int m_line, m_column;
Mark m_mark;
std::string m_anchor, m_tag;
Content *m_pContent;
bool m_alias;

View File

@@ -15,7 +15,7 @@ namespace YAML
template <typename T>
inline void operator >> (const Node& node, T& value) {
if(!node.Read(value))
throw InvalidScalar(node.m_line, node.m_column);
throw InvalidScalar(node.m_mark);
}
template <typename T>
@@ -51,7 +51,7 @@ namespace YAML
}
}
throw MakeTypedKeyNotFound(m_line, m_column, key);
throw MakeTypedKeyNotFound(m_mark, key);
}
template <typename T>