diff --git a/node.cpp b/node.cpp index c31fe96..78a2793 100644 --- a/node.cpp +++ b/node.cpp @@ -83,10 +83,10 @@ namespace YAML void Node::ParseTag(Scanner *pScanner, const ParserState& state) { - if(m_tag != "") - return; // TODO: throw - Token *pToken = pScanner->PeekNextToken(); + if(m_tag != "") + throw ParserException(pToken->line, pToken->column, "cannot assign multiple tags to the same node"); + m_tag = state.TranslateTag(pToken->value); for(unsigned i=0;iparams.size();i++) @@ -96,10 +96,10 @@ namespace YAML void Node::ParseAnchor(Scanner *pScanner, const ParserState& state) { - if(m_anchor != "") - return; // TODO: throw - Token *pToken = pScanner->PeekNextToken(); + if(m_anchor != "") + throw ParserException(pToken->line, pToken->column, "cannot assign multiple anchors to the same node"); + m_anchor = pToken->value; m_alias = false; pScanner->PopNextToken(); @@ -107,12 +107,12 @@ namespace YAML void Node::ParseAlias(Scanner *pScanner, const ParserState& state) { - if(m_anchor != "") - return; // TODO: throw - if(m_tag != "") - return; // TODO: throw (aliases can't have any content, *including* tags) - Token *pToken = pScanner->PeekNextToken(); + if(m_anchor != "") + throw ParserException(pToken->line, pToken->column, "cannot assign multiple aliases to the same node"); + if(m_tag != "") + throw ParserException(pToken->line, pToken->column, "aliases can't have any content, *including* tags"); + m_anchor = pToken->value; m_alias = true; pScanner->PopNextToken(); diff --git a/parser.cpp b/parser.cpp index 82935d1..f27a344 100644 --- a/parser.cpp +++ b/parser.cpp @@ -96,13 +96,17 @@ namespace YAML str >> m_state.version.major; str.get(); str >> m_state.version.minor; - if(!str) - throw ParserException(pToken->line, pToken->column, "bad YAML directive"); - // TODO: or throw if there are any more characters in the stream? + if(!str || str.peek() != EOF) + throw ParserException(pToken->line, pToken->column, "bad YAML version: " + pToken->params[0]); - // TODO: throw on major > 1? warning on major == 1, minor > 2? + if(m_state.version.major > 1) + throw ParserException(pToken->line, pToken->column, "YAML major version > 1"); + + // TODO: warning on major == 1, minor > 2? } + // HandleTagDirective + // . Should be of the form 'handle prefix', where 'handle' is converted to 'prefix' in the file. void Parser::HandleTagDirective(Token *pToken) { if(pToken->params.size() != 2) diff --git a/tests.cpp b/tests.cpp index 98b5a3b..ad41f67 100644 --- a/tests.cpp +++ b/tests.cpp @@ -16,6 +16,7 @@ namespace YAML files.push_back("tests/simple.yaml"); files.push_back("tests/mixed.yaml"); files.push_back("tests/scalars.yaml"); + files.push_back("tests/directives.yaml"); bool passed = true; for(unsigned i=0;i