mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Added CMake scripts for other platforms\nFixed some bugs that gcc complained about\nFixed CR/LF vs LF bug
This commit is contained in:
parent
813817f1ab
commit
ec2ecad197
30 changed files with 233 additions and 82 deletions
4
CMakeLists.txt
Normal file
4
CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
project (YAML_CPP)
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
add_subdirectory (src)
|
||||
add_subdirectory (yaml-reader)
|
|
@ -7,4 +7,5 @@
|
|||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
|
||||
#endif // _DEBUG
|
||||
#endif // _DEBUG
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace YAML
|
|||
public:
|
||||
ParserException(int line_, int column_, const std::string& msg_)
|
||||
: line(line_), column(column_), msg(msg_) {}
|
||||
virtual ~ParserException() throw () {}
|
||||
|
||||
int line, column;
|
||||
std::string msg;
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
#include "parser.h"
|
||||
#include "node.h"
|
||||
#include "iterator.h"
|
||||
#include "exceptions.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
|
|
7
src/CMakeLists.txt
Normal file
7
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
set(FILES content.cpp iterator.cpp node.cpp parserstate.cpp
|
||||
scalar.cpp scanscalar.cpp sequence.cpp stream.cpp
|
||||
exp.cpp map.cpp parser.cpp regex.cpp scanner.cpp
|
||||
scantoken.cpp simplekey.cpp)
|
||||
|
||||
include_directories(${YAML_CPP_SOURCE_DIR}/include)
|
||||
add_library(yaml-cpp ${FILES})
|
|
@ -16,8 +16,6 @@ namespace YAML
|
|||
class Sequence;
|
||||
class Map;
|
||||
|
||||
enum CONTENT_TYPE;
|
||||
|
||||
class Content
|
||||
{
|
||||
public:
|
||||
|
@ -33,7 +31,9 @@ namespace YAML
|
|||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
||||
virtual Node *GetNode(unsigned i) const { return 0; }
|
||||
virtual unsigned GetSize() const { return 0; }
|
||||
virtual CONTENT_TYPE GetType() const = 0;
|
||||
virtual bool IsScalar() const { return false; }
|
||||
virtual bool IsMap() const { return false; }
|
||||
virtual bool IsSequence() const { return false; }
|
||||
|
||||
// extraction
|
||||
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace YAML
|
|||
{
|
||||
// misc
|
||||
const RegEx Blank = RegEx(' ') || RegEx('\t');
|
||||
const RegEx Break = RegEx('\n');
|
||||
const RegEx Break = RegEx('\n') || RegEx("\r\n");
|
||||
const RegEx BlankOrBreak = Blank || Break;
|
||||
const RegEx Digit = RegEx('0', '9');
|
||||
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||
|
|
12
src/map.cpp
12
src/map.cpp
|
@ -3,7 +3,8 @@
|
|||
#include "node.h"
|
||||
#include "scanner.h"
|
||||
#include "token.h"
|
||||
#include "exceptions.h"
|
||||
#include "exceptions.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
@ -142,7 +143,7 @@ namespace YAML
|
|||
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||
{
|
||||
if(startedLine && !onlyOneCharOnLine)
|
||||
out << std::endl;
|
||||
out << "\n";
|
||||
|
||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
||||
|
@ -160,12 +161,7 @@ namespace YAML
|
|||
}
|
||||
|
||||
if(m_data.empty())
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
CONTENT_TYPE Map::GetType() const
|
||||
{
|
||||
return CT_MAP;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
int Map::Compare(Content *pContent)
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace YAML
|
|||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsMap() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
|
|
21
src/node.cpp
21
src/node.cpp
|
@ -122,23 +122,23 @@ namespace YAML
|
|||
// write anchor/alias
|
||||
if(m_anchor != "") {
|
||||
if(m_alias)
|
||||
out << "*";
|
||||
out << std::string("*");
|
||||
else
|
||||
out << "&";
|
||||
out << m_anchor << " ";
|
||||
out << std::string("&");
|
||||
out << m_anchor << std::string(" ");
|
||||
startedLine = true;
|
||||
onlyOneCharOnLine = false;
|
||||
}
|
||||
|
||||
// write tag
|
||||
if(m_tag != "") {
|
||||
out << "!<" << m_tag << "> ";
|
||||
out << std::string("!<") << m_tag << std::string("> ");
|
||||
startedLine = true;
|
||||
onlyOneCharOnLine = false;
|
||||
}
|
||||
|
||||
if(!m_pContent) {
|
||||
out << std::endl;
|
||||
out << std::string("\n");
|
||||
} else {
|
||||
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
||||
}
|
||||
|
@ -148,8 +148,15 @@ namespace YAML
|
|||
{
|
||||
if(!m_pContent)
|
||||
return CT_NONE;
|
||||
|
||||
return m_pContent->GetType();
|
||||
|
||||
if(m_pContent->IsScalar())
|
||||
return CT_SCALAR;
|
||||
else if(m_pContent->IsSequence())
|
||||
return CT_SEQUENCE;
|
||||
else if(m_pContent->IsMap())
|
||||
return CT_MAP;
|
||||
|
||||
return CT_NONE;
|
||||
}
|
||||
|
||||
// begin
|
||||
|
|
|
@ -121,12 +121,12 @@ namespace YAML
|
|||
}
|
||||
|
||||
void Parser::PrintTokens(std::ostream& out)
|
||||
{
|
||||
{
|
||||
while(1) {
|
||||
if(m_pScanner->empty())
|
||||
break;
|
||||
|
||||
out << m_pScanner->peek() << std::endl;
|
||||
out << m_pScanner->peek() << "\n";
|
||||
m_pScanner->pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "crt.h"
|
||||
#include "regex.h"
|
||||
#include "regex.h"
|
||||
#include "stream.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
@ -88,6 +90,11 @@ namespace YAML
|
|||
}
|
||||
|
||||
bool RegEx::Matches(std::istream& in) const
|
||||
{
|
||||
return Match(in) >= 0;
|
||||
}
|
||||
|
||||
bool RegEx::Matches(Stream& in) const
|
||||
{
|
||||
return Match(in) >= 0;
|
||||
}
|
||||
|
@ -106,6 +113,12 @@ namespace YAML
|
|||
return m_pOp->Match(str, *this);
|
||||
}
|
||||
|
||||
// Match
|
||||
int RegEx::Match(Stream& in) const
|
||||
{
|
||||
return Match(in.stream());
|
||||
}
|
||||
|
||||
// Match
|
||||
// . The stream version does the same thing as the string version;
|
||||
// REMEMBER that we only match from the start of the stream!
|
||||
|
|
10
src/regex.h
10
src/regex.h
|
@ -5,7 +5,9 @@
|
|||
#include <ios>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
{
|
||||
class Stream;
|
||||
|
||||
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
||||
|
||||
// simplified regular expressions
|
||||
|
@ -64,9 +66,11 @@ namespace YAML
|
|||
|
||||
bool Matches(char ch) const;
|
||||
bool Matches(const std::string& str) const;
|
||||
bool Matches(std::istream& in) const;
|
||||
bool Matches(std::istream& in) const;
|
||||
bool Matches(Stream& in) const;
|
||||
int Match(const std::string& str) const;
|
||||
int Match(std::istream& in) const;
|
||||
int Match(std::istream& in) const;
|
||||
int Match(Stream& in) const;
|
||||
|
||||
friend RegEx operator ! (const RegEx& ex);
|
||||
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
||||
|
|
|
@ -38,11 +38,6 @@ namespace YAML
|
|||
out << "\"\n";
|
||||
}
|
||||
|
||||
CONTENT_TYPE Scalar::GetType() const
|
||||
{
|
||||
return CT_SCALAR;
|
||||
}
|
||||
|
||||
void Scalar::Read(std::string& s)
|
||||
{
|
||||
s = m_data;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace YAML
|
|||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsScalar() const { return true; }
|
||||
|
||||
// extraction
|
||||
virtual void Read(std::string& s);
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
#include "sequence.h"
|
||||
#include "node.h"
|
||||
#include "scanner.h"
|
||||
#include "token.h"
|
||||
#include "token.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
@ -134,7 +135,7 @@ namespace YAML
|
|||
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||
{
|
||||
if(startedLine && !onlyOneCharOnLine)
|
||||
out << std::endl;
|
||||
out << "\n";
|
||||
|
||||
for(unsigned i=0;i<m_data.size();i++) {
|
||||
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
||||
|
@ -147,12 +148,7 @@ namespace YAML
|
|||
}
|
||||
|
||||
if(m_data.empty())
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
CONTENT_TYPE Sequence::GetType() const
|
||||
{
|
||||
return CT_SEQUENCE;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
int Sequence::Compare(Content *pContent)
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace YAML
|
|||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||
|
||||
virtual CONTENT_TYPE GetType() const;
|
||||
virtual bool IsSequence() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
#include "crt.h"
|
||||
#include "stream.h"
|
||||
#include "stream.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
int Stream::pos() const
|
||||
{
|
||||
return input.tellg();
|
||||
}
|
||||
|
||||
char Stream::peek()
|
||||
{
|
||||
return input.peek();
|
||||
}
|
||||
|
||||
Stream::operator bool()
|
||||
{
|
||||
return input.good();
|
||||
}
|
||||
|
||||
// get
|
||||
// . Extracts a character from the stream and updates our position
|
||||
char Stream::get()
|
||||
|
@ -32,5 +48,6 @@ namespace YAML
|
|||
{
|
||||
for(int i=0;i<n;i++)
|
||||
get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
10
src/stream.h
10
src/stream.h
|
@ -9,12 +9,12 @@ namespace YAML
|
|||
{
|
||||
Stream(std::istream& input_): input(input_), line(0), column(0) {}
|
||||
|
||||
int pos() const { return input.tellg(); }
|
||||
operator std::istream& () { return input; }
|
||||
operator bool() { return input.good(); }
|
||||
bool operator !() { return !input; }
|
||||
int pos() const;
|
||||
operator bool();
|
||||
bool operator !() { return !(*this); }
|
||||
|
||||
char peek() { return input.peek(); }
|
||||
std::istream& stream() const { return input; }
|
||||
char peek();
|
||||
char get();
|
||||
std::string get(int n);
|
||||
void eat(int n = 1);
|
||||
|
|
|
@ -53,9 +53,9 @@ namespace YAML
|
|||
Token(TOKEN_TYPE type_, int line_, int column_): status(TS_VALID), type(type_), line(line_), column(column_) {}
|
||||
|
||||
friend std::ostream& operator << (std::ostream& out, const Token& token) {
|
||||
out << TokenNames[token.type] << ": " << token.value;
|
||||
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||
for(unsigned i=0;i<token.params.size();i++)
|
||||
out << " " << token.params[i];
|
||||
out << std::string(" ") << token.params[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
6
yaml-reader/CMakeLists.txt
Normal file
6
yaml-reader/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
set(FILES main.cpp tests.cpp)
|
||||
include_directories(${YAML_CPP_SOURCE_DIR}/include)
|
||||
link_directories(${YAML_CPP_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(yaml-reader ${FILES})
|
||||
target_link_libraries(yaml-reader yaml-cpp)
|
|
@ -11,31 +11,29 @@
|
|||
|
||||
void run()
|
||||
{
|
||||
std::ifstream fin("yaml-reader/tests/test.yaml");
|
||||
std::ifstream fin("tests/test.yaml");
|
||||
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
if(!parser)
|
||||
return;
|
||||
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
|
||||
std::string item;
|
||||
*it >> item;
|
||||
std::cout << item << "\n";
|
||||
}
|
||||
YAML::Parser parser(fin);
|
||||
parser.PrintTokens(std::cout);
|
||||
} catch(YAML::Exception&) {
|
||||
std::cout << "Error parsing the yaml!\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
||||
Test::RunAll();
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool verbose = false;
|
||||
for(int i=1;i<argc;i++) {
|
||||
if(strcmp(argv[i], "-v") == 0)
|
||||
verbose = true;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
||||
#endif // WINDOWS
|
||||
Test::RunAll(verbose);
|
||||
run();
|
||||
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,20 +9,21 @@
|
|||
namespace Test
|
||||
{
|
||||
// runs all the tests on all data we have
|
||||
void RunAll()
|
||||
void RunAll(bool verbose)
|
||||
{
|
||||
std::vector <std::string> files;
|
||||
files.push_back("yaml-reader/tests/simple.yaml");
|
||||
files.push_back("yaml-reader/tests/mixed.yaml");
|
||||
files.push_back("yaml-reader/tests/scalars.yaml");
|
||||
files.push_back("yaml-reader/tests/directives.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<files.size();i++) {
|
||||
if(!Inout(files[i])) {
|
||||
std::cout << "Inout test failed on " << files[i] << std::endl;
|
||||
if(!Inout(files[i], verbose)) {
|
||||
std::cout << "Inout test failed on " << files[i] << "\n";
|
||||
passed = false;
|
||||
}
|
||||
} else
|
||||
std::cout << "Inout test passed: " << files[i] << "\n";
|
||||
}
|
||||
|
||||
if(passed)
|
||||
|
@ -31,9 +32,9 @@ namespace Test
|
|||
|
||||
// loads the given YAML file, outputs it, and then loads the outputted file,
|
||||
// outputs again, and makes sure that the two outputs are the same
|
||||
bool Inout(const std::string& file)
|
||||
bool Inout(const std::string& file, bool verbose)
|
||||
{
|
||||
std::ifstream fin(file.c_str());
|
||||
std::ifstream fin(file.c_str());
|
||||
|
||||
try {
|
||||
// read and output
|
||||
|
@ -70,7 +71,15 @@ namespace Test
|
|||
fout << "---\n";
|
||||
fout << secondTry << std::endl;
|
||||
} catch(YAML::ParserException& e) {
|
||||
std::cout << file << " (line " << e.line + 1 << ", col " << e.column + 1 << "): " << e.msg << std::endl;
|
||||
std::cout << file << " (line " << e.line + 1 << ", col " << e.column + 1 << "): " << e.msg << std::endl;
|
||||
|
||||
if(verbose) {
|
||||
std::cout << "Token queue:\n";
|
||||
std::ifstream f(file.c_str());
|
||||
YAML::Parser p(f);
|
||||
p.PrintTokens(std::cout);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <string>
|
||||
|
||||
namespace Test {
|
||||
void RunAll();
|
||||
bool Inout(const std::string& file);
|
||||
void RunAll(bool verbose);
|
||||
bool Inout(const std::string& file, bool verbose);
|
||||
}
|
||||
|
|
5
yaml-reader/tests/directives.yaml
Normal file
5
yaml-reader/tests/directives.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
%YAML 1.2
|
||||
%TAG ! !howdy
|
||||
---
|
||||
- basic node
|
||||
- ! yeah baby
|
32
yaml-reader/tests/mixed.yaml
Normal file
32
yaml-reader/tests/mixed.yaml
Normal file
|
@ -0,0 +1,32 @@
|
|||
- the main thing is a sequence
|
||||
- here's a key: value
|
||||
and another: value
|
||||
- let's inline: [1, 2, 3]
|
||||
and an inline map: {key: value, 243: 101}
|
||||
- and multiple indents:
|
||||
- here's
|
||||
- a
|
||||
- list
|
||||
and another:
|
||||
- list
|
||||
- of
|
||||
- things
|
||||
- maybe now:
|
||||
let's: get
|
||||
pretty:
|
||||
deep: here
|
||||
in:
|
||||
the: nesting
|
||||
just: to
|
||||
confuse:
|
||||
the: heck
|
||||
out:
|
||||
- of
|
||||
- the: parser
|
||||
if:
|
||||
- we
|
||||
- can
|
||||
- do: that
|
||||
what: do
|
||||
you: think?
|
||||
|
8
yaml-reader/tests/out.yaml
Normal file
8
yaml-reader/tests/out.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- "basic node"
|
||||
- !<!howdy> "yeah baby"
|
||||
|
||||
---
|
||||
- "basic node"
|
||||
- !<!<!howdy>> "yeah baby"
|
||||
|
35
yaml-reader/tests/scalars.yaml
Normal file
35
yaml-reader/tests/scalars.yaml
Normal file
|
@ -0,0 +1,35 @@
|
|||
- normal scalar, but
|
||||
over several lines
|
||||
- |
|
||||
literal scalar - so we can draw ASCII:
|
||||
|
||||
- -
|
||||
| - |
|
||||
------
|
||||
- >
|
||||
and a folded scalar... so we
|
||||
can just keep writing various
|
||||
things. And if we want to keep indentation:
|
||||
|
||||
we just indent a little
|
||||
see, this stays indented
|
||||
- >-
|
||||
Here's a folded scalar
|
||||
that gets chomped.
|
||||
- |-
|
||||
And here's a literal scalar
|
||||
that gets chomped.
|
||||
- >2
|
||||
Here's a folded scalar
|
||||
that starts with some indentation.
|
||||
- ::vector
|
||||
- ": - ()"
|
||||
- Up, up, and away!
|
||||
- -123
|
||||
- http://example.com/foo#bar
|
||||
# Inside flow collection:
|
||||
- [ ::vector,
|
||||
": - ()",
|
||||
"Up, up and away!",
|
||||
-123,
|
||||
http://example.com/foo#bar ]
|
13
yaml-reader/tests/simple.yaml
Normal file
13
yaml-reader/tests/simple.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
just a scalar
|
||||
---
|
||||
and another scalar
|
||||
---
|
||||
now an end document
|
||||
...
|
||||
---
|
||||
and now two
|
||||
...
|
||||
...
|
||||
---
|
||||
and that's it
|
3
yaml-reader/tests/test.yaml
Normal file
3
yaml-reader/tests/test.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- it's just
|
||||
- one thing
|
||||
- after another
|
Loading…
Add table
Add a link
Reference in a new issue