Commit ec2ecad1 authored by Jesse Beder's avatar Jesse Beder
Browse files

Added CMake scripts for other platforms\nFixed some bugs that gcc complained...

Added CMake scripts for other platforms\nFixed some bugs that gcc complained about\nFixed CR/LF vs LF bug
parent 813817f1
project (YAML_CPP)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
add_subdirectory (src)
add_subdirectory (yaml-reader)
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <crtdbg.h> #include <crtdbg.h>
#endif // _DEBUG #endif // _DEBUG
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace YAML ...@@ -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;
......
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
#include "parser.h" #include "parser.h"
#include "node.h" #include "node.h"
#include "iterator.h" #include "iterator.h"
#include "exceptions.h" #include "exceptions.h"
\ No newline at end of file
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 ...@@ -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 ...@@ -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 ...@@ -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');
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include "node.h" #include "node.h"
#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 ...@@ -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 ...@@ -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 ...@@ -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);
......
...@@ -122,23 +122,23 @@ namespace YAML ...@@ -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);
} }
...@@ -148,8 +148,15 @@ namespace YAML ...@@ -148,8 +148,15 @@ 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
......
...@@ -121,12 +121,12 @@ namespace YAML ...@@ -121,12 +121,12 @@ namespace YAML
} }
void Parser::PrintTokens(std::ostream& out) void Parser::PrintTokens(std::ostream& out)
{ {
while(1) { while(1) {
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();
} }
} }
......
#include "crt.h" #include "crt.h"
#include "regex.h" #include "regex.h"
#include "stream.h"
#include <iostream>
namespace YAML namespace YAML
{ {
...@@ -88,6 +90,11 @@ namespace YAML ...@@ -88,6 +90,11 @@ namespace YAML
} }
bool RegEx::Matches(std::istream& in) const bool RegEx::Matches(std::istream& in) const
{
return Match(in) >= 0;
}
bool RegEx::Matches(Stream& in) const
{ {
return Match(in) >= 0; return Match(in) >= 0;
} }
...@@ -106,6 +113,12 @@ namespace YAML ...@@ -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!
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include <ios> #include <ios>
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
...@@ -64,9 +66,11 @@ namespace YAML ...@@ -64,9 +66,11 @@ 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 ...@@ -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 ...@@ -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);
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#include "sequence.h" #include "sequence.h"
#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 ...@@ -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 ...@@ -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 ...@@ -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);
......
#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()
...@@ -32,5 +48,6 @@ namespace YAML ...@@ -32,5 +48,6 @@ namespace YAML
{ {
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
get(); get();
} }
} }
...@@ -9,12 +9,12 @@ namespace YAML ...@@ -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 ...@@ -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;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment