mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Removed the document class (since it's really just a root node, and that's it).
This commit is contained in:
parent
2be40919de
commit
ed488e5197
7 changed files with 27 additions and 103 deletions
63
document.cpp
63
document.cpp
|
@ -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;
|
||||
}
|
||||
}
|
26
document.h
26
document.h
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <ios>
|
||||
#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;
|
||||
};
|
||||
}
|
4
main.cpp
4
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";
|
||||
|
|
1
node.h
1
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;
|
||||
|
|
24
parser.cpp
24
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;
|
||||
|
|
4
parser.h
4
parser.h
|
@ -4,7 +4,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#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:
|
||||
|
|
|
@ -216,10 +216,6 @@
|
|||
RelativePath=".\content.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\document.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\iterator.cpp"
|
||||
>
|
||||
|
@ -298,10 +294,6 @@
|
|||
RelativePath=".\content.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\document.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\map.h"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue