diff --git a/document.cpp b/document.cpp deleted file mode 100644 index 8d4d55f341..0000000000 --- a/document.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "document.h" -#include "node.h" -#include "token.h" -#include "scanner.h" - -namespace YAML -{ - Document::Document(): m_pRoot(0) - { - } - - Document::~Document() - { - Clear(); - } - - void Document::Clear() - { - delete m_pRoot; - m_pRoot = 0; - } - - void Document::Parse(Scanner *pScanner, const ParserState& state) - { - Clear(); - - // we better have some tokens in the queue - if(!pScanner->PeekNextToken()) - return; - - // first eat doc start (optional) - if(pScanner->PeekNextToken()->type == TT_DOC_START) - pScanner->EatNextToken(); - - // now create our root node and parse it - m_pRoot = new Node; - m_pRoot->Parse(pScanner, state); - - // and finally eat any doc ends we see - while(pScanner->PeekNextToken() && pScanner->PeekNextToken()->type == TT_DOC_END) - pScanner->EatNextToken(); - } - - const Node& Document::GetRoot() const - { - if(!m_pRoot) - throw; - - return *m_pRoot; - } - - std::ostream& operator << (std::ostream& out, const Document& doc) - { - out << "---\n"; - if(!doc.m_pRoot) { - out << "{empty node}\n"; - return out; - } - - doc.m_pRoot->Write(out, 0); - return out; - } -} diff --git a/document.h b/document.h deleted file mode 100644 index 3517cf07b0..0000000000 --- a/document.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include "parserstate.h" - -namespace YAML -{ - class Node; - class Scanner; - - class Document - { - public: - Document(); - ~Document(); - - void Clear(); - void Parse(Scanner *pScanner, const ParserState& state); - const Node& GetRoot() const; - - friend std::ostream& operator << (std::ostream& out, const Document& doc); - - private: - Node *m_pRoot; - }; -} diff --git a/main.cpp b/main.cpp index acf1114c6c..d1b5d28dab 100644 --- a/main.cpp +++ b/main.cpp @@ -72,11 +72,11 @@ int main() if(!parser) return 0; - YAML::Document doc; + YAML::Node doc; parser.GetNextDocument(doc); Level level; - doc.GetRoot() >> level; + doc >> level; std::cout << level; } catch(YAML::Exception&) { std::cout << "Error parsing the yaml!\n"; diff --git a/node.h b/node.h index 47f659b39d..a86ba153e7 100644 --- a/node.h +++ b/node.h @@ -48,6 +48,7 @@ namespace YAML void Parse(Scanner *pScanner, const ParserState& state); void Write(std::ostream& out, int indent); + // accessors Iterator begin() const; Iterator end() const; unsigned size() const; diff --git a/parser.cpp b/parser.cpp index 7b42d43550..decb6630f7 100644 --- a/parser.cpp +++ b/parser.cpp @@ -22,15 +22,35 @@ namespace YAML return m_pScanner->PeekNextToken() != 0; } - void Parser::GetNextDocument(Document& document) + // GetNextDocument + // . Reads the next document in the queue (of tokens). + // . Throws (ScannerException|ParserException)s on errors. + void Parser::GetNextDocument(Node& document) { + // clear node + document.Clear(); + // first read directives ParseDirectives(); - // then parse the document + // we better have some tokens in the queue + if(!m_pScanner->PeekNextToken()) + return; + + // first eat doc start (optional) + if(m_pScanner->PeekNextToken()->type == TT_DOC_START) + m_pScanner->EatNextToken(); + + // now parse our root node document.Parse(m_pScanner, m_state); + + // and finally eat any doc ends we see + while(m_pScanner->PeekNextToken() && m_pScanner->PeekNextToken()->type == TT_DOC_END) + m_pScanner->EatNextToken(); } + // ParseDirectives + // . Reads any directives that are next in the queue. void Parser::ParseDirectives() { bool readDirective = false; diff --git a/parser.h b/parser.h index cd42017320..a26446f902 100644 --- a/parser.h +++ b/parser.h @@ -4,7 +4,7 @@ #include #include #include -#include "document.h" +#include "node.h" #include "parserstate.h" namespace YAML @@ -20,7 +20,7 @@ namespace YAML operator bool() const; - void GetNextDocument(Document& document); + void GetNextDocument(Node& document); void PrintTokens(std::ostream& out); private: diff --git a/yaml-reader.vcproj b/yaml-reader.vcproj index 4e74139bb6..455b71d421 100644 --- a/yaml-reader.vcproj +++ b/yaml-reader.vcproj @@ -216,10 +216,6 @@ RelativePath=".\content.cpp" > - - @@ -298,10 +294,6 @@ RelativePath=".\content.h" > - -