Merge 5b1c606801 into c2bec4c755
This commit is contained in:
commit
e46c4576f8
@ -48,6 +48,14 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef YAML_CPP_NORETURN
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
# define YAML_CPP_NORETURN __declspec(noreturn)
|
||||||
|
# else
|
||||||
|
# define YAML_CPP_NORETURN __attribute__ ((noreturn))
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef YAML_CPP_DEPRECATED_EXPORT
|
#ifndef YAML_CPP_DEPRECATED_EXPORT
|
||||||
# define YAML_CPP_DEPRECATED_EXPORT YAML_CPP_API YAML_CPP_DEPRECATED
|
# define YAML_CPP_DEPRECATED_EXPORT YAML_CPP_API YAML_CPP_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -15,6 +15,21 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
|
|
||||||
|
#if defined(__cpp_exceptions) || (defined(_MSC_VER) && defined(_CPPUNWIND))
|
||||||
|
template<typename Ex, typename... Args>
|
||||||
|
YAML_CPP_NORETURN void YAML_throw(Args&&... args) {
|
||||||
|
throw Ex(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
YAML_CPP_NORETURN void handle_exception(const char* what);
|
||||||
|
|
||||||
|
template<typename Ex, typename... Args>
|
||||||
|
YAML_CPP_NORETURN void YAML_throw(Args&&... args) {
|
||||||
|
handle_exception(Ex(std::forward<Args>(args)...).what());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// error messages
|
// error messages
|
||||||
namespace ErrorMsg {
|
namespace ErrorMsg {
|
||||||
const char* const YAML_DIRECTIVE_ARGS =
|
const char* const YAML_DIRECTIVE_ARGS =
|
||||||
|
|||||||
@ -128,7 +128,7 @@ inline node* node_data::get(const Key& key,
|
|||||||
return pNode;
|
return pNode;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
YAML_throw<BadSubscript>(m_mark, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
||||||
@ -154,7 +154,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
YAML_throw<BadSubscript>(m_mark, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
|
||||||
@ -213,7 +213,7 @@ inline void node_data::force_insert(const Key& key, const Value& value,
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadInsert();
|
YAML_throw<BadInsert>();
|
||||||
}
|
}
|
||||||
|
|
||||||
node& k = convert_to_node(key, pMemory);
|
node& k = convert_to_node(key, pMemory);
|
||||||
|
|||||||
@ -57,7 +57,7 @@ inline Node::~Node() = default;
|
|||||||
|
|
||||||
inline void Node::EnsureNodeExists() const {
|
inline void Node::EnsureNodeExists() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
if (!m_pNode) {
|
if (!m_pNode) {
|
||||||
m_pMemory.reset(new detail::memory_holder);
|
m_pMemory.reset(new detail::memory_holder);
|
||||||
m_pNode = &m_pMemory->create_node();
|
m_pNode = &m_pMemory->create_node();
|
||||||
@ -74,14 +74,14 @@ inline bool Node::IsDefined() const {
|
|||||||
|
|
||||||
inline Mark Node::Mark() const {
|
inline Mark Node::Mark() const {
|
||||||
if (!m_isValid) {
|
if (!m_isValid) {
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
}
|
}
|
||||||
return m_pNode ? m_pNode->mark() : Mark::null_mark();
|
return m_pNode ? m_pNode->mark() : Mark::null_mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeType::value Node::Type() const {
|
inline NodeType::value Node::Type() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->type() : NodeType::Null;
|
return m_pNode ? m_pNode->type() : NodeType::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +125,12 @@ struct as_if<T, void> {
|
|||||||
|
|
||||||
T operator()() const {
|
T operator()() const {
|
||||||
if (!node.m_pNode)
|
if (!node.m_pNode)
|
||||||
throw TypedBadConversion<T>(node.Mark());
|
YAML_throw<TypedBadConversion<T> >(node.Mark());
|
||||||
|
|
||||||
T t;
|
T t;
|
||||||
if (convert<T>::decode(node, t))
|
if (convert<T>::decode(node, t))
|
||||||
return t;
|
return t;
|
||||||
throw TypedBadConversion<T>(node.Mark());
|
YAML_throw<TypedBadConversion<T> >(node.Mark());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ struct as_if<std::string, void> {
|
|||||||
if (node.Type() == NodeType::Null)
|
if (node.Type() == NodeType::Null)
|
||||||
return "null";
|
return "null";
|
||||||
if (node.Type() != NodeType::Scalar)
|
if (node.Type() != NodeType::Scalar)
|
||||||
throw TypedBadConversion<std::string>(node.Mark());
|
YAML_throw<TypedBadConversion<std::string> >(node.Mark());
|
||||||
return node.Scalar();
|
return node.Scalar();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -152,7 +152,7 @@ struct as_if<std::string, void> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline T Node::as() const {
|
inline T Node::as() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return as_if<T, void>(*this)();
|
return as_if<T, void>(*this)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,13 +165,13 @@ inline T Node::as(const S& fallback) const {
|
|||||||
|
|
||||||
inline const std::string& Node::Scalar() const {
|
inline const std::string& Node::Scalar() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar();
|
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string& Node::Tag() const {
|
inline const std::string& Node::Tag() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
|
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ inline void Node::SetTag(const std::string& tag) {
|
|||||||
|
|
||||||
inline EmitterStyle::value Node::Style() const {
|
inline EmitterStyle::value Node::Style() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
|
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ inline void Node::SetStyle(EmitterStyle::value style) {
|
|||||||
// assignment
|
// assignment
|
||||||
inline bool Node::is(const Node& rhs) const {
|
inline bool Node::is(const Node& rhs) const {
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
if (!m_pNode || !rhs.m_pNode)
|
if (!m_pNode || !rhs.m_pNode)
|
||||||
return false;
|
return false;
|
||||||
return m_pNode->is(*rhs.m_pNode);
|
return m_pNode->is(*rhs.m_pNode);
|
||||||
@ -215,7 +215,7 @@ inline Node& Node::operator=(const Node& rhs) {
|
|||||||
|
|
||||||
inline void Node::reset(const YAML::Node& rhs) {
|
inline void Node::reset(const YAML::Node& rhs) {
|
||||||
if (!m_isValid || !rhs.m_isValid)
|
if (!m_isValid || !rhs.m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
m_pMemory = rhs.m_pMemory;
|
m_pMemory = rhs.m_pMemory;
|
||||||
m_pNode = rhs.m_pNode;
|
m_pNode = rhs.m_pNode;
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ inline void Node::reset(const YAML::Node& rhs) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::Assign(const T& rhs) {
|
inline void Node::Assign(const T& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
AssignData(convert<T>::encode(rhs));
|
AssignData(convert<T>::encode(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ inline void Node::AssignData(const Node& rhs) {
|
|||||||
|
|
||||||
inline void Node::AssignNode(const Node& rhs) {
|
inline void Node::AssignNode(const Node& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
rhs.EnsureNodeExists();
|
rhs.EnsureNodeExists();
|
||||||
|
|
||||||
if (!m_pNode) {
|
if (!m_pNode) {
|
||||||
@ -270,7 +270,7 @@ inline void Node::AssignNode(const Node& rhs) {
|
|||||||
// size/iterator
|
// size/iterator
|
||||||
inline std::size_t Node::size() const {
|
inline std::size_t Node::size() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
return m_pNode ? m_pNode->size() : 0;
|
return m_pNode ? m_pNode->size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ inline iterator Node::end() {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline void Node::push_back(const T& rhs) {
|
inline void Node::push_back(const T& rhs) {
|
||||||
if (!m_isValid)
|
if (!m_isValid)
|
||||||
throw InvalidNode(m_invalidKey);
|
YAML_throw<InvalidNode>(m_invalidKey);
|
||||||
push_back(Node(rhs));
|
push_back(Node(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ unsigned ParseHex(const std::string& str, const Mark& mark) {
|
|||||||
else if ('0' <= ch && ch <= '9')
|
else if ('0' <= ch && ch <= '9')
|
||||||
digit = ch - '0';
|
digit = ch - '0';
|
||||||
else
|
else
|
||||||
throw ParserException(mark, ErrorMsg::INVALID_HEX);
|
YAML_throw<ParserException>(mark, ErrorMsg::INVALID_HEX);
|
||||||
|
|
||||||
value = (value << 4) + digit;
|
value = (value << 4) + digit;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ std::string Escape(Stream& in, int codeLength) {
|
|||||||
if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
|
if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
msg << ErrorMsg::INVALID_UNICODE << value;
|
msg << ErrorMsg::INVALID_UNICODE << value;
|
||||||
throw ParserException(in.mark(), msg.str());
|
YAML_throw<ParserException>(in.mark(), msg.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// now break it up into chars
|
// now break it up into chars
|
||||||
@ -131,7 +131,7 @@ std::string Escape(Stream& in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
throw ParserException(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch);
|
YAML_throw<ParserException>(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch);
|
||||||
}
|
}
|
||||||
} // namespace Exp
|
} // namespace Exp
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
@ -184,7 +184,7 @@ void node_data::push_back(node& node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_type != NodeType::Sequence)
|
if (m_type != NodeType::Sequence)
|
||||||
throw BadPushback();
|
YAML_throw<BadPushback>();
|
||||||
|
|
||||||
m_sequence.push_back(&node);
|
m_sequence.push_back(&node);
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ void node_data::insert(node& key, node& value,
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
YAML_throw<BadSubscript>(m_mark, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_map_pair(key, value);
|
insert_map_pair(key, value);
|
||||||
@ -231,7 +231,7 @@ node& node_data::get(node& key, const shared_memory_holder& pMemory) {
|
|||||||
convert_to_map(pMemory);
|
convert_to_map(pMemory);
|
||||||
break;
|
break;
|
||||||
case NodeType::Scalar:
|
case NodeType::Scalar:
|
||||||
throw BadSubscript(m_mark, key);
|
YAML_throw<BadSubscript>(m_mark, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& it : m_map) {
|
for (const auto& it : m_map) {
|
||||||
|
|||||||
@ -32,7 +32,7 @@ Node Load(std::istream& input) {
|
|||||||
Node LoadFile(const std::string& filename) {
|
Node LoadFile(const std::string& filename) {
|
||||||
std::ifstream fin(filename);
|
std::ifstream fin(filename);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
throw BadFile(filename);
|
YAML_throw<BadFile>(filename);
|
||||||
}
|
}
|
||||||
return Load(fin);
|
return Load(fin);
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ std::vector<Node> LoadAll(std::istream& input) {
|
|||||||
std::vector<Node> LoadAllFromFile(const std::string& filename) {
|
std::vector<Node> LoadAllFromFile(const std::string& filename) {
|
||||||
std::ifstream fin(filename);
|
std::ifstream fin(filename);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
throw BadFile(filename);
|
YAML_throw<BadFile>(filename);
|
||||||
}
|
}
|
||||||
return LoadAll(fin);
|
return LoadAll(fin);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,11 +69,11 @@ void Parser::HandleDirective(const Token& token) {
|
|||||||
|
|
||||||
void Parser::HandleYamlDirective(const Token& token) {
|
void Parser::HandleYamlDirective(const Token& token) {
|
||||||
if (token.params.size() != 1) {
|
if (token.params.size() != 1) {
|
||||||
throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_pDirectives->version.isDefault) {
|
if (!m_pDirectives->version.isDefault) {
|
||||||
throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream str(token.params[0]);
|
std::stringstream str(token.params[0]);
|
||||||
@ -87,7 +87,7 @@ void Parser::HandleYamlDirective(const Token& token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pDirectives->version.major > 1) {
|
if (m_pDirectives->version.major > 1) {
|
||||||
throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::YAML_MAJOR_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pDirectives->version.isDefault = false;
|
m_pDirectives->version.isDefault = false;
|
||||||
@ -96,12 +96,12 @@ void Parser::HandleYamlDirective(const Token& token) {
|
|||||||
|
|
||||||
void Parser::HandleTagDirective(const Token& token) {
|
void Parser::HandleTagDirective(const Token& token) {
|
||||||
if (token.params.size() != 2)
|
if (token.params.size() != 2)
|
||||||
throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS);
|
||||||
|
|
||||||
const std::string& handle = token.params[0];
|
const std::string& handle = token.params[0];
|
||||||
const std::string& prefix = token.params[1];
|
const std::string& prefix = token.params[1];
|
||||||
if (m_pDirectives->tags.find(handle) != m_pDirectives->tags.end()) {
|
if (m_pDirectives->tags.find(handle) != m_pDirectives->tags.end()) {
|
||||||
throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pDirectives->tags[handle] = prefix;
|
m_pDirectives->tags[handle] = prefix;
|
||||||
|
|||||||
@ -189,7 +189,7 @@ void Scanner::ScanNextToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// don't know what it is!
|
// don't know what it is!
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::UNKNOWN_TOKEN);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::UNKNOWN_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scanner::ScanToNextToken() {
|
void Scanner::ScanToNextToken() {
|
||||||
@ -410,6 +410,6 @@ void Scanner::ThrowParserException(const std::string& msg) const {
|
|||||||
const Token& token = m_tokens.front();
|
const Token& token = m_tokens.front();
|
||||||
mark = token.mark;
|
mark = token.mark;
|
||||||
}
|
}
|
||||||
throw ParserException(mark, msg);
|
YAML_throw<ParserException>(mark, msg);
|
||||||
}
|
}
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
@ -49,7 +49,7 @@ std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (params.onDocIndicator == THROW) {
|
if (params.onDocIndicator == THROW) {
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
|
|||||||
// eof? if we're looking to eat something, then we throw
|
// eof? if we're looking to eat something, then we throw
|
||||||
if (!INPUT) {
|
if (!INPUT) {
|
||||||
if (params.eatEnd) {
|
if (params.eatEnd) {
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
|
|||||||
// we check for tabs that masquerade as indentation
|
// we check for tabs that masquerade as indentation
|
||||||
if (INPUT.peek() == '\t' && INPUT.column() < params.indent &&
|
if (INPUT.peek() == '\t' && INPUT.column() < params.indent &&
|
||||||
params.onTabInIndentation == THROW) {
|
params.onTabInIndentation == THROW) {
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.eatLeadingWhitespace) {
|
if (!params.eatLeadingWhitespace) {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ const std::string ScanVerbatimTag(Stream& INPUT) {
|
|||||||
tag += INPUT.get(n);
|
tag += INPUT.get(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
|
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
|
||||||
@ -37,7 +37,7 @@ const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
|
|||||||
while (INPUT) {
|
while (INPUT) {
|
||||||
if (INPUT.peek() == Keys::Tag) {
|
if (INPUT.peek() == Keys::Tag) {
|
||||||
if (!canBeHandle)
|
if (!canBeHandle)
|
||||||
throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
|
YAML_throw<ParserException>(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ const std::string ScanTagSuffix(Stream& INPUT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag.empty())
|
if (tag.empty())
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,7 +103,7 @@ void Scanner::ScanFlowStart() {
|
|||||||
// FlowEnd
|
// FlowEnd
|
||||||
void Scanner::ScanFlowEnd() {
|
void Scanner::ScanFlowEnd() {
|
||||||
if (InBlockContext())
|
if (InBlockContext())
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::FLOW_END);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::FLOW_END);
|
||||||
|
|
||||||
// we might have a solo entry in the flow context
|
// we might have a solo entry in the flow context
|
||||||
if (InFlowContext()) {
|
if (InFlowContext()) {
|
||||||
@ -123,7 +123,7 @@ void Scanner::ScanFlowEnd() {
|
|||||||
// check that it matches the start
|
// check that it matches the start
|
||||||
FLOW_MARKER flowType = (ch == Keys::FlowSeqEnd ? FLOW_SEQ : FLOW_MAP);
|
FLOW_MARKER flowType = (ch == Keys::FlowSeqEnd ? FLOW_SEQ : FLOW_MAP);
|
||||||
if (m_flows.top() != flowType)
|
if (m_flows.top() != flowType)
|
||||||
throw ParserException(mark, ErrorMsg::FLOW_END);
|
YAML_throw<ParserException>(mark, ErrorMsg::FLOW_END);
|
||||||
m_flows.pop();
|
m_flows.pop();
|
||||||
|
|
||||||
Token::TYPE type = (flowType ? Token::FLOW_SEQ_END : Token::FLOW_MAP_END);
|
Token::TYPE type = (flowType ? Token::FLOW_SEQ_END : Token::FLOW_MAP_END);
|
||||||
@ -153,11 +153,11 @@ void Scanner::ScanFlowEntry() {
|
|||||||
void Scanner::ScanBlockEntry() {
|
void Scanner::ScanBlockEntry() {
|
||||||
// we better be in the block context!
|
// we better be in the block context!
|
||||||
if (InFlowContext())
|
if (InFlowContext())
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
|
||||||
|
|
||||||
// can we put it here?
|
// can we put it here?
|
||||||
if (!m_simpleKeyAllowed)
|
if (!m_simpleKeyAllowed)
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
|
||||||
|
|
||||||
PushIndentTo(INPUT.column(), IndentMarker::SEQ);
|
PushIndentTo(INPUT.column(), IndentMarker::SEQ);
|
||||||
m_simpleKeyAllowed = true;
|
m_simpleKeyAllowed = true;
|
||||||
@ -174,7 +174,7 @@ void Scanner::ScanKey() {
|
|||||||
// handle keys differently in the block context (and manage indents)
|
// handle keys differently in the block context (and manage indents)
|
||||||
if (InBlockContext()) {
|
if (InBlockContext()) {
|
||||||
if (!m_simpleKeyAllowed)
|
if (!m_simpleKeyAllowed)
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::MAP_KEY);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::MAP_KEY);
|
||||||
|
|
||||||
PushIndentTo(INPUT.column(), IndentMarker::MAP);
|
PushIndentTo(INPUT.column(), IndentMarker::MAP);
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ void Scanner::ScanValue() {
|
|||||||
// handle values differently in the block context (and manage indents)
|
// handle values differently in the block context (and manage indents)
|
||||||
if (InBlockContext()) {
|
if (InBlockContext()) {
|
||||||
if (!m_simpleKeyAllowed)
|
if (!m_simpleKeyAllowed)
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::MAP_VALUE);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::MAP_VALUE);
|
||||||
|
|
||||||
PushIndentTo(INPUT.column(), IndentMarker::MAP);
|
PushIndentTo(INPUT.column(), IndentMarker::MAP);
|
||||||
}
|
}
|
||||||
@ -241,12 +241,12 @@ void Scanner::ScanAnchorOrAlias() {
|
|||||||
|
|
||||||
// we need to have read SOMETHING!
|
// we need to have read SOMETHING!
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND
|
YAML_throw<ParserException>(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND
|
||||||
: ErrorMsg::ANCHOR_NOT_FOUND);
|
: ErrorMsg::ANCHOR_NOT_FOUND);
|
||||||
|
|
||||||
// and needs to end correctly
|
// and needs to end correctly
|
||||||
if (INPUT && !Exp::AnchorEnd().Matches(INPUT))
|
if (INPUT && !Exp::AnchorEnd().Matches(INPUT))
|
||||||
throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS
|
YAML_throw<ParserException>(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS
|
||||||
: ErrorMsg::CHAR_IN_ANCHOR);
|
: ErrorMsg::CHAR_IN_ANCHOR);
|
||||||
|
|
||||||
// and we're done
|
// and we're done
|
||||||
@ -323,7 +323,7 @@ void Scanner::ScanPlainScalar() {
|
|||||||
|
|
||||||
// finally, check and see if we ended on an illegal character
|
// finally, check and see if we ended on an illegal character
|
||||||
// if(Exp::IllegalCharInScalar.Matches(INPUT))
|
// if(Exp::IllegalCharInScalar.Matches(INPUT))
|
||||||
// throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR);
|
// YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR);
|
||||||
|
|
||||||
Token token(Token::PLAIN_SCALAR, mark);
|
Token token(Token::PLAIN_SCALAR, mark);
|
||||||
token.value = scalar;
|
token.value = scalar;
|
||||||
@ -402,7 +402,7 @@ void Scanner::ScanBlockScalar() {
|
|||||||
params.chomp = STRIP;
|
params.chomp = STRIP;
|
||||||
else if (Exp::Digit().Matches(ch)) {
|
else if (Exp::Digit().Matches(ch)) {
|
||||||
if (ch == '0')
|
if (ch == '0')
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::ZERO_INDENT_IN_BLOCK);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::ZERO_INDENT_IN_BLOCK);
|
||||||
|
|
||||||
params.indent = ch - '0';
|
params.indent = ch - '0';
|
||||||
params.detectIndent = false;
|
params.detectIndent = false;
|
||||||
@ -420,7 +420,7 @@ void Scanner::ScanBlockScalar() {
|
|||||||
|
|
||||||
// if it's not a line break, then we ran into a bad character inline
|
// if it's not a line break, then we ran into a bad character inline
|
||||||
if (INPUT && !Exp::Break().Matches(INPUT))
|
if (INPUT && !Exp::Break().Matches(INPUT))
|
||||||
throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_BLOCK);
|
YAML_throw<ParserException>(INPUT.mark(), ErrorMsg::CHAR_IN_BLOCK);
|
||||||
|
|
||||||
// set the initial indentation
|
// set the initial indentation
|
||||||
if (GetTopIndent() >= 0)
|
if (GetTopIndent() >= 0)
|
||||||
|
|||||||
@ -168,11 +168,11 @@ void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
|
||||||
|
|
||||||
Token token = m_scanner.peek();
|
Token token = m_scanner.peek();
|
||||||
if (token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
|
if (token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
|
||||||
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::END_OF_SEQ);
|
||||||
|
|
||||||
m_scanner.pop();
|
m_scanner.pop();
|
||||||
if (token.type == Token::BLOCK_SEQ_END)
|
if (token.type == Token::BLOCK_SEQ_END)
|
||||||
@ -201,7 +201,7 @@ void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
|
||||||
|
|
||||||
// first check for end
|
// first check for end
|
||||||
if (m_scanner.peek().type == Token::FLOW_SEQ_END) {
|
if (m_scanner.peek().type == Token::FLOW_SEQ_END) {
|
||||||
@ -213,7 +213,7 @@ void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler) {
|
|||||||
HandleNode(eventHandler);
|
HandleNode(eventHandler);
|
||||||
|
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
|
||||||
|
|
||||||
// now eat the separator (or could be a sequence end, which we ignore - but
|
// now eat the separator (or could be a sequence end, which we ignore - but
|
||||||
// if it's neither, then it's a bad node)
|
// if it's neither, then it's a bad node)
|
||||||
@ -221,7 +221,7 @@ void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler) {
|
|||||||
if (token.type == Token::FLOW_ENTRY)
|
if (token.type == Token::FLOW_ENTRY)
|
||||||
m_scanner.pop();
|
m_scanner.pop();
|
||||||
else if (token.type != Token::FLOW_SEQ_END)
|
else if (token.type != Token::FLOW_SEQ_END)
|
||||||
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ_FLOW);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::END_OF_SEQ_FLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCollectionStack->PopCollectionType(CollectionType::FlowSeq);
|
m_pCollectionStack->PopCollectionType(CollectionType::FlowSeq);
|
||||||
@ -254,12 +254,12 @@ void SingleDocParser::HandleBlockMap(EventHandler& eventHandler) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_MAP);
|
||||||
|
|
||||||
Token token = m_scanner.peek();
|
Token token = m_scanner.peek();
|
||||||
if (token.type != Token::KEY && token.type != Token::VALUE &&
|
if (token.type != Token::KEY && token.type != Token::VALUE &&
|
||||||
token.type != Token::BLOCK_MAP_END)
|
token.type != Token::BLOCK_MAP_END)
|
||||||
throw ParserException(token.mark, ErrorMsg::END_OF_MAP);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::END_OF_MAP);
|
||||||
|
|
||||||
if (token.type == Token::BLOCK_MAP_END) {
|
if (token.type == Token::BLOCK_MAP_END) {
|
||||||
m_scanner.pop();
|
m_scanner.pop();
|
||||||
@ -293,7 +293,7 @@ void SingleDocParser::HandleFlowMap(EventHandler& eventHandler) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
|
||||||
|
|
||||||
Token& token = m_scanner.peek();
|
Token& token = m_scanner.peek();
|
||||||
const Mark mark = token.mark;
|
const Mark mark = token.mark;
|
||||||
@ -320,7 +320,7 @@ void SingleDocParser::HandleFlowMap(EventHandler& eventHandler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_scanner.empty())
|
if (m_scanner.empty())
|
||||||
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
|
YAML_throw<ParserException>(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
|
||||||
|
|
||||||
// now eat the separator (or could be a map end, which we ignore - but if
|
// now eat the separator (or could be a map end, which we ignore - but if
|
||||||
// it's neither, then it's a bad node)
|
// it's neither, then it's a bad node)
|
||||||
@ -328,7 +328,7 @@ void SingleDocParser::HandleFlowMap(EventHandler& eventHandler) {
|
|||||||
if (nextToken.type == Token::FLOW_ENTRY)
|
if (nextToken.type == Token::FLOW_ENTRY)
|
||||||
m_scanner.pop();
|
m_scanner.pop();
|
||||||
else if (nextToken.type != Token::FLOW_MAP_END)
|
else if (nextToken.type != Token::FLOW_MAP_END)
|
||||||
throw ParserException(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW);
|
YAML_throw<ParserException>(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCollectionStack->PopCollectionType(CollectionType::FlowMap);
|
m_pCollectionStack->PopCollectionType(CollectionType::FlowMap);
|
||||||
@ -396,7 +396,7 @@ void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor,
|
|||||||
void SingleDocParser::ParseTag(std::string& tag) {
|
void SingleDocParser::ParseTag(std::string& tag) {
|
||||||
Token& token = m_scanner.peek();
|
Token& token = m_scanner.peek();
|
||||||
if (!tag.empty())
|
if (!tag.empty())
|
||||||
throw ParserException(token.mark, ErrorMsg::MULTIPLE_TAGS);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::MULTIPLE_TAGS);
|
||||||
|
|
||||||
Tag tagInfo(token);
|
Tag tagInfo(token);
|
||||||
tag = tagInfo.Translate(m_directives);
|
tag = tagInfo.Translate(m_directives);
|
||||||
@ -406,7 +406,7 @@ void SingleDocParser::ParseTag(std::string& tag) {
|
|||||||
void SingleDocParser::ParseAnchor(anchor_t& anchor, std::string& anchor_name) {
|
void SingleDocParser::ParseAnchor(anchor_t& anchor, std::string& anchor_name) {
|
||||||
Token& token = m_scanner.peek();
|
Token& token = m_scanner.peek();
|
||||||
if (anchor)
|
if (anchor)
|
||||||
throw ParserException(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
|
YAML_throw<ParserException>(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
|
||||||
|
|
||||||
anchor_name = token.value;
|
anchor_name = token.value;
|
||||||
anchor = RegisterAnchor(token.value);
|
anchor = RegisterAnchor(token.value);
|
||||||
@ -426,7 +426,7 @@ anchor_t SingleDocParser::LookupAnchor(const Mark& mark,
|
|||||||
if (it == m_anchors.end()) {
|
if (it == m_anchors.end()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << ErrorMsg::UNKNOWN_ANCHOR << name;
|
ss << ErrorMsg::UNKNOWN_ANCHOR << name;
|
||||||
throw ParserException(mark, ss.str());
|
YAML_throw<ParserException>(mark, ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user