mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00: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:
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)
|
@@ -8,3 +8,4 @@
|
|||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
|
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ namespace YAML
|
|||||||
public:
|
public:
|
||||||
ParserException(int line_, int column_, const std::string& msg_)
|
ParserException(int line_, int column_, const std::string& msg_)
|
||||||
: line(line_), column(column_), msg(msg_) {}
|
: line(line_), column(column_), msg(msg_) {}
|
||||||
|
virtual ~ParserException() throw () {}
|
||||||
|
|
||||||
int line, column;
|
int line, column;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
@@ -5,3 +5,4 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "iterator.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 Sequence;
|
||||||
class Map;
|
class Map;
|
||||||
|
|
||||||
enum CONTENT_TYPE;
|
|
||||||
|
|
||||||
class Content
|
class Content
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +31,9 @@ namespace YAML
|
|||||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
|
||||||
virtual Node *GetNode(unsigned i) const { return 0; }
|
virtual Node *GetNode(unsigned i) const { return 0; }
|
||||||
virtual unsigned GetSize() 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
|
// extraction
|
||||||
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
virtual void Read(std::string& s) { throw InvalidScalar(); }
|
||||||
|
@@ -14,7 +14,7 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
// misc
|
// misc
|
||||||
const RegEx Blank = RegEx(' ') || RegEx('\t');
|
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 BlankOrBreak = Blank || Break;
|
||||||
const RegEx Digit = RegEx('0', '9');
|
const RegEx Digit = RegEx('0', '9');
|
||||||
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||||
|
10
src/map.cpp
10
src/map.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -142,7 +143,7 @@ namespace YAML
|
|||||||
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
void Map::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||||
{
|
{
|
||||||
if(startedLine && !onlyOneCharOnLine)
|
if(startedLine && !onlyOneCharOnLine)
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
|
|
||||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||||
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
if((startedLine && !onlyOneCharOnLine) || it != m_data.begin()) {
|
||||||
@@ -160,12 +161,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(m_data.empty())
|
if(m_data.empty())
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
}
|
|
||||||
|
|
||||||
CONTENT_TYPE Map::GetType() const
|
|
||||||
{
|
|
||||||
return CT_MAP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::Compare(Content *pContent)
|
int Map::Compare(Content *pContent)
|
||||||
|
@@ -19,7 +19,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsMap() const { return true; }
|
||||||
|
|
||||||
// ordering
|
// ordering
|
||||||
virtual int Compare(Content *pContent);
|
virtual int Compare(Content *pContent);
|
||||||
|
19
src/node.cpp
19
src/node.cpp
@@ -122,23 +122,23 @@ namespace YAML
|
|||||||
// write anchor/alias
|
// write anchor/alias
|
||||||
if(m_anchor != "") {
|
if(m_anchor != "") {
|
||||||
if(m_alias)
|
if(m_alias)
|
||||||
out << "*";
|
out << std::string("*");
|
||||||
else
|
else
|
||||||
out << "&";
|
out << std::string("&");
|
||||||
out << m_anchor << " ";
|
out << m_anchor << std::string(" ");
|
||||||
startedLine = true;
|
startedLine = true;
|
||||||
onlyOneCharOnLine = false;
|
onlyOneCharOnLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write tag
|
// write tag
|
||||||
if(m_tag != "") {
|
if(m_tag != "") {
|
||||||
out << "!<" << m_tag << "> ";
|
out << std::string("!<") << m_tag << std::string("> ");
|
||||||
startedLine = true;
|
startedLine = true;
|
||||||
onlyOneCharOnLine = false;
|
onlyOneCharOnLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!m_pContent) {
|
if(!m_pContent) {
|
||||||
out << std::endl;
|
out << std::string("\n");
|
||||||
} else {
|
} else {
|
||||||
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,14 @@ namespace YAML
|
|||||||
if(!m_pContent)
|
if(!m_pContent)
|
||||||
return CT_NONE;
|
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
|
// begin
|
||||||
|
@@ -126,7 +126,7 @@ namespace YAML
|
|||||||
if(m_pScanner->empty())
|
if(m_pScanner->empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
out << m_pScanner->peek() << std::endl;
|
out << m_pScanner->peek() << "\n";
|
||||||
m_pScanner->pop();
|
m_pScanner->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
#include "crt.h"
|
#include "crt.h"
|
||||||
#include "regex.h"
|
#include "regex.h"
|
||||||
|
#include "stream.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -92,6 +94,11 @@ namespace YAML
|
|||||||
return Match(in) >= 0;
|
return Match(in) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RegEx::Matches(Stream& in) const
|
||||||
|
{
|
||||||
|
return Match(in) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Match
|
// Match
|
||||||
// . Matches the given string against this regular expression.
|
// . Matches the given string against this regular expression.
|
||||||
// . Returns the number of characters matched.
|
// . Returns the number of characters matched.
|
||||||
@@ -106,6 +113,12 @@ namespace YAML
|
|||||||
return m_pOp->Match(str, *this);
|
return m_pOp->Match(str, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Match
|
||||||
|
int RegEx::Match(Stream& in) const
|
||||||
|
{
|
||||||
|
return Match(in.stream());
|
||||||
|
}
|
||||||
|
|
||||||
// Match
|
// Match
|
||||||
// . The stream version does the same thing as the string version;
|
// . The stream version does the same thing as the string version;
|
||||||
// REMEMBER that we only match from the start of the stream!
|
// REMEMBER that we only match from the start of the stream!
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
class Stream;
|
||||||
|
|
||||||
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ };
|
||||||
|
|
||||||
// simplified regular expressions
|
// simplified regular expressions
|
||||||
@@ -65,8 +67,10 @@ namespace YAML
|
|||||||
bool Matches(char ch) const;
|
bool Matches(char ch) const;
|
||||||
bool Matches(const std::string& str) 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(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& ex);
|
||||||
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
||||||
|
@@ -38,11 +38,6 @@ namespace YAML
|
|||||||
out << "\"\n";
|
out << "\"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
CONTENT_TYPE Scalar::GetType() const
|
|
||||||
{
|
|
||||||
return CT_SCALAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scalar::Read(std::string& s)
|
void Scalar::Read(std::string& s)
|
||||||
{
|
{
|
||||||
s = m_data;
|
s = m_data;
|
||||||
|
@@ -14,7 +14,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsScalar() const { return true; }
|
||||||
|
|
||||||
// extraction
|
// extraction
|
||||||
virtual void Read(std::string& s);
|
virtual void Read(std::string& s);
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -134,7 +135,7 @@ namespace YAML
|
|||||||
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
void Sequence::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine)
|
||||||
{
|
{
|
||||||
if(startedLine && !onlyOneCharOnLine)
|
if(startedLine && !onlyOneCharOnLine)
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
|
|
||||||
for(unsigned i=0;i<m_data.size();i++) {
|
for(unsigned i=0;i<m_data.size();i++) {
|
||||||
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
if((startedLine && !onlyOneCharOnLine) || i > 0) {
|
||||||
@@ -147,12 +148,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(m_data.empty())
|
if(m_data.empty())
|
||||||
out << std::endl;
|
out << "\n";
|
||||||
}
|
|
||||||
|
|
||||||
CONTENT_TYPE Sequence::GetType() const
|
|
||||||
{
|
|
||||||
return CT_SEQUENCE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sequence::Compare(Content *pContent)
|
int Sequence::Compare(Content *pContent)
|
||||||
|
@@ -22,7 +22,7 @@ namespace YAML
|
|||||||
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
virtual void Parse(Scanner *pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual CONTENT_TYPE GetType() const;
|
virtual bool IsSequence() const { return true; }
|
||||||
|
|
||||||
// ordering
|
// ordering
|
||||||
virtual int Compare(Content *pContent);
|
virtual int Compare(Content *pContent);
|
||||||
|
@@ -1,8 +1,24 @@
|
|||||||
#include "crt.h"
|
#include "crt.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
int Stream::pos() const
|
||||||
|
{
|
||||||
|
return input.tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
char Stream::peek()
|
||||||
|
{
|
||||||
|
return input.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream::operator bool()
|
||||||
|
{
|
||||||
|
return input.good();
|
||||||
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
// . Extracts a character from the stream and updates our position
|
// . Extracts a character from the stream and updates our position
|
||||||
char Stream::get()
|
char Stream::get()
|
||||||
@@ -33,4 +49,5 @@ namespace YAML
|
|||||||
for(int i=0;i<n;i++)
|
for(int i=0;i<n;i++)
|
||||||
get();
|
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) {}
|
Stream(std::istream& input_): input(input_), line(0), column(0) {}
|
||||||
|
|
||||||
int pos() const { return input.tellg(); }
|
int pos() const;
|
||||||
operator std::istream& () { return input; }
|
operator bool();
|
||||||
operator bool() { return input.good(); }
|
bool operator !() { return !(*this); }
|
||||||
bool operator !() { return !input; }
|
|
||||||
|
|
||||||
char peek() { return input.peek(); }
|
std::istream& stream() const { return input; }
|
||||||
|
char peek();
|
||||||
char get();
|
char get();
|
||||||
std::string get(int n);
|
std::string get(int n);
|
||||||
void eat(int n = 1);
|
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_) {}
|
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) {
|
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++)
|
for(unsigned i=0;i<token.params.size();i++)
|
||||||
out << " " << token.params[i];
|
out << std::string(" ") << token.params[i];
|
||||||
return out;
|
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()
|
void run()
|
||||||
{
|
{
|
||||||
std::ifstream fin("yaml-reader/tests/test.yaml");
|
std::ifstream fin("tests/test.yaml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
YAML::Parser parser(fin);
|
YAML::Parser parser(fin);
|
||||||
if(!parser)
|
parser.PrintTokens(std::cout);
|
||||||
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";
|
|
||||||
}
|
|
||||||
} catch(YAML::Exception&) {
|
} catch(YAML::Exception&) {
|
||||||
std::cout << "Error parsing the yaml!\n";
|
std::cout << "Error parsing the yaml!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
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);
|
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
||||||
Test::RunAll();
|
#endif // WINDOWS
|
||||||
|
Test::RunAll(verbose);
|
||||||
run();
|
run();
|
||||||
|
|
||||||
getchar();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -9,20 +9,21 @@
|
|||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
// runs all the tests on all data we have
|
// runs all the tests on all data we have
|
||||||
void RunAll()
|
void RunAll(bool verbose)
|
||||||
{
|
{
|
||||||
std::vector <std::string> files;
|
std::vector <std::string> files;
|
||||||
files.push_back("yaml-reader/tests/simple.yaml");
|
files.push_back("tests/simple.yaml");
|
||||||
files.push_back("yaml-reader/tests/mixed.yaml");
|
files.push_back("tests/mixed.yaml");
|
||||||
files.push_back("yaml-reader/tests/scalars.yaml");
|
files.push_back("tests/scalars.yaml");
|
||||||
files.push_back("yaml-reader/tests/directives.yaml");
|
files.push_back("tests/directives.yaml");
|
||||||
|
|
||||||
bool passed = true;
|
bool passed = true;
|
||||||
for(unsigned i=0;i<files.size();i++) {
|
for(unsigned i=0;i<files.size();i++) {
|
||||||
if(!Inout(files[i])) {
|
if(!Inout(files[i], verbose)) {
|
||||||
std::cout << "Inout test failed on " << files[i] << std::endl;
|
std::cout << "Inout test failed on " << files[i] << "\n";
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
} else
|
||||||
|
std::cout << "Inout test passed: " << files[i] << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(passed)
|
if(passed)
|
||||||
@@ -31,7 +32,7 @@ namespace Test
|
|||||||
|
|
||||||
// loads the given YAML file, outputs it, and then loads the outputted file,
|
// 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
|
// 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());
|
||||||
|
|
||||||
@@ -71,6 +72,14 @@ namespace Test
|
|||||||
fout << secondTry << std::endl;
|
fout << secondTry << std::endl;
|
||||||
} catch(YAML::ParserException& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
void RunAll();
|
void RunAll(bool verbose);
|
||||||
bool Inout(const std::string& file);
|
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
|
Reference in New Issue
Block a user