Commit 3355bbb3 authored by Jesse Beder's avatar Jesse Beder
Browse files

Merge clang-format from core

parents 5b889311 9b4db068
#ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <ios>
#include <string>
#include <queue>
......@@ -16,28 +17,35 @@
#include "stream.h"
#include "token.h"
namespace YAML
{
class Node;
class RegEx;
namespace YAML {
class Node;
class RegEx;
class Scanner
{
class Scanner {
public:
Scanner(std::istream& in);
Scanner(std::istream &in);
~Scanner();
// token queue management (hopefully this looks kinda stl-ish)
bool empty();
void pop();
Token& peek();
Token &peek();
Mark mark() const;
private:
struct IndentMarker {
enum INDENT_TYPE { MAP, SEQ, NONE };
enum STATUS { VALID, INVALID, UNKNOWN };
IndentMarker(int column_, INDENT_TYPE type_): column(column_), type(type_), status(VALID), pStartToken(0) {}
enum INDENT_TYPE {
MAP,
SEQ,
NONE
};
enum STATUS {
VALID,
INVALID,
UNKNOWN
};
IndentMarker(int column_, INDENT_TYPE type_)
: column(column_), type(type_), status(VALID), pStartToken(0) {}
int column;
INDENT_TYPE type;
......@@ -45,7 +53,10 @@ namespace YAML
Token *pStartToken;
};
enum FLOW_MARKER { FLOW_MAP, FLOW_SEQ };
enum FLOW_MARKER {
FLOW_MAP,
FLOW_SEQ
};
private:
// scanning
......@@ -75,13 +86,13 @@ namespace YAML
bool VerifySimpleKey();
void PopAllSimpleKeys();
void ThrowParserException(const std::string& msg) const;
void ThrowParserException(const std::string &msg) const;
bool IsWhitespaceToBeEaten(char ch);
const RegEx& GetValueRegex() const;
const RegEx &GetValueRegex() const;
struct SimpleKey {
SimpleKey(const Mark& mark_, int flowLevel_);
SimpleKey(const Mark &mark_, int flowLevel_);
void Validate();
void Invalidate();
......@@ -126,8 +137,7 @@ namespace YAML
std::stack<IndentMarker *> m_indents;
ptr_vector<IndentMarker> m_indentRefs; // for "garbage collection"
std::stack<FLOW_MARKER> m_flows;
};
};
}
#endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -4,20 +4,18 @@
#include "yaml-cpp/exceptions.h"
#include "token.h"
namespace YAML
{
// ScanScalar
// . This is where the scalar magic happens.
//
// . We do the scanning in three phases:
// 1. Scan until newline
// 2. Eat newline
// 3. Scan leading blanks.
//
// . Depending on the parameters given, we store or stop
// and different places in the above flow.
std::string ScanScalar(Stream& INPUT, ScanScalarParams& params)
{
namespace YAML {
// ScanScalar
// . This is where the scalar magic happens.
//
// . We do the scanning in three phases:
// 1. Scan until newline
// 2. Eat newline
// 3. Scan leading blanks.
//
// . Depending on the parameters given, we store or stop
// and different places in the above flow.
std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
bool foundNonEmptyLine = false;
bool pastOpeningBreak = (params.fold == FOLD_FLOW);
bool emptyLine = false, moreIndented = false;
......@@ -27,21 +25,21 @@ namespace YAML
std::string scalar;
params.leadingSpaces = false;
while(INPUT) {
while (INPUT) {
// ********************************
// Phase #1: scan until line ending
std::size_t lastNonWhitespaceChar = scalar.size();
bool escapedNewline = false;
while(!params.end.Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
if(!INPUT)
while (!params.end.Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
if (!INPUT)
break;
// document indicator?
if(INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
if(params.onDocIndicator == BREAK)
if (INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
if (params.onDocIndicator == BREAK)
break;
else if(params.onDocIndicator == THROW)
else if (params.onDocIndicator == THROW)
throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
}
......@@ -49,7 +47,7 @@ namespace YAML
pastOpeningBreak = true;
// escaped newline? (only if we're escaping on slash)
if(params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
if (params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
// eat escape character and get out (but preserve trailing whitespace!)
INPUT.get();
lastNonWhitespaceChar = scalar.size();
......@@ -59,7 +57,7 @@ namespace YAML
}
// escape this?
if(INPUT.peek() == params.escape) {
if (INPUT.peek() == params.escape) {
scalar += Exp::Escape(INPUT);
lastNonWhitespaceChar = scalar.size();
lastEscapedChar = scalar.size();
......@@ -69,31 +67,32 @@ namespace YAML
// otherwise, just add the damn character
char ch = INPUT.get();
scalar += ch;
if(ch != ' ' && ch != '\t')
if (ch != ' ' && ch != '\t')
lastNonWhitespaceChar = scalar.size();
}
// eof? if we're looking to eat something, then we throw
if(!INPUT) {
if(params.eatEnd)
if (!INPUT) {
if (params.eatEnd)
throw ParserException(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);
break;
}
// doc indicator?
if(params.onDocIndicator == BREAK && INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT))
if (params.onDocIndicator == BREAK && INPUT.column() == 0 &&
Exp::DocIndicator().Matches(INPUT))
break;
// are we done via character match?
int n = params.end.Match(INPUT);
if(n >= 0) {
if(params.eatEnd)
if (n >= 0) {
if (params.eatEnd)
INPUT.eat(n);
break;
}
// do we remove trailing whitespace?
if(params.fold == FOLD_FLOW)
if (params.fold == FOLD_FLOW)
scalar.erase(lastNonWhitespaceChar);
// ********************************
......@@ -105,20 +104,22 @@ namespace YAML
// Phase #3: scan initial spaces
// first the required indentation
while(INPUT.peek() == ' ' && (INPUT.column() < params.indent || (params.detectIndent && !foundNonEmptyLine)))
while (INPUT.peek() == ' ' && (INPUT.column() < params.indent ||
(params.detectIndent && !foundNonEmptyLine)))
INPUT.eat(1);
// update indent if we're auto-detecting
if(params.detectIndent && !foundNonEmptyLine)
if (params.detectIndent && !foundNonEmptyLine)
params.indent = std::max(params.indent, INPUT.column());
// and then the rest of the whitespace
while(Exp::Blank().Matches(INPUT)) {
while (Exp::Blank().Matches(INPUT)) {
// we check for tabs that masquerade as indentation
if(INPUT.peek() == '\t'&& INPUT.column() < params.indent && params.onTabInIndentation == THROW)
if (INPUT.peek() == '\t' && INPUT.column() < params.indent &&
params.onTabInIndentation == THROW)
throw ParserException(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);
if(!params.eatLeadingWhitespace)
if (!params.eatLeadingWhitespace)
break;
INPUT.eat(1);
......@@ -127,34 +128,37 @@ namespace YAML
// was this an empty line?
bool nextEmptyLine = Exp::Break().Matches(INPUT);
bool nextMoreIndented = Exp::Blank().Matches(INPUT);
if(params.fold == FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
if (params.fold == FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
foldedNewlineStartedMoreIndented = moreIndented;
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
if(pastOpeningBreak) {
switch(params.fold) {
// for block scalars, we always start with a newline, so we should ignore it
// (not fold or keep)
if (pastOpeningBreak) {
switch (params.fold) {
case DONT_FOLD:
scalar += "\n";
break;
case FOLD_BLOCK:
if(!emptyLine && !nextEmptyLine && !moreIndented && !nextMoreIndented && INPUT.column() >= params.indent)
if (!emptyLine && !nextEmptyLine && !moreIndented &&
!nextMoreIndented && INPUT.column() >= params.indent)
scalar += " ";
else if(nextEmptyLine)
else if (nextEmptyLine)
foldedNewlineCount++;
else
scalar += "\n";
if(!nextEmptyLine && foldedNewlineCount > 0) {
if (!nextEmptyLine && foldedNewlineCount > 0) {
scalar += std::string(foldedNewlineCount - 1, '\n');
if(foldedNewlineStartedMoreIndented || nextMoreIndented | !foundNonEmptyLine)
if (foldedNewlineStartedMoreIndented ||
nextMoreIndented | !foundNonEmptyLine)
scalar += "\n";
foldedNewlineCount = 0;
}
break;
case FOLD_FLOW:
if(nextEmptyLine)
if (nextEmptyLine)
scalar += "\n";
else if(!emptyLine && !nextEmptyLine && !escapedNewline)
else if (!emptyLine && !nextEmptyLine && !escapedNewline)
scalar += " ";
break;
}
......@@ -165,44 +169,44 @@ namespace YAML
pastOpeningBreak = true;
// are we done via indentation?
if(!emptyLine && INPUT.column() < params.indent) {
if (!emptyLine && INPUT.column() < params.indent) {
params.leadingSpaces = true;
break;
}
}
// post-processing
if(params.trimTrailingSpaces) {
if (params.trimTrailingSpaces) {
std::size_t pos = scalar.find_last_not_of(' ');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos < scalar.size())
if (pos < scalar.size())
scalar.erase(pos + 1);
}
switch(params.chomp) {
switch (params.chomp) {
case CLIP: {
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
if (pos == std::string::npos)
scalar.erase();
else if(pos + 1 < scalar.size())
else if (pos + 1 < scalar.size())
scalar.erase(pos + 2);
} break;
case STRIP: {
std::size_t pos = scalar.find_last_not_of('\n');
if(lastEscapedChar != std::string::npos) {
if(pos < lastEscapedChar || pos == std::string::npos)
if (lastEscapedChar != std::string::npos) {
if (pos < lastEscapedChar || pos == std::string::npos)
pos = lastEscapedChar;
}
if(pos == std::string::npos)
if (pos == std::string::npos)
scalar.erase();
else if(pos < scalar.size())
else if (pos < scalar.size())
scalar.erase(pos + 1);
} break;
default:
......@@ -210,5 +214,5 @@ namespace YAML
}
return scalar;
}
}
}
#ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include "regex.h"
#include "stream.h"
namespace YAML
{
enum CHOMP { STRIP = -1, CLIP, KEEP };
enum ACTION { NONE, BREAK, THROW };
enum FOLD { DONT_FOLD, FOLD_BLOCK, FOLD_FLOW };
namespace YAML {
enum CHOMP {
STRIP = -1,
CLIP,
KEEP
};
enum ACTION {
NONE,
BREAK,
THROW
};
enum FOLD {
DONT_FOLD,
FOLD_BLOCK,
FOLD_FLOW
};
struct ScanScalarParams {
ScanScalarParams(): eatEnd(false), indent(0), detectIndent(false), eatLeadingWhitespace(0), escape(0), fold(DONT_FOLD),
trimTrailingSpaces(0), chomp(CLIP), onDocIndicator(NONE), onTabInIndentation(NONE), leadingSpaces(false) {}
struct ScanScalarParams {
ScanScalarParams()
: eatEnd(false),
indent(0),
detectIndent(false),
eatLeadingWhitespace(0),
escape(0),
fold(DONT_FOLD),
trimTrailingSpaces(0),
chomp(CLIP),
onDocIndicator(NONE),
onTabInIndentation(NONE),
leadingSpaces(false) {}
// input:
RegEx end; // what condition ends this scalar?
bool eatEnd; // should we eat that condition when we see it?
int indent; // what level of indentation should be eaten and ignored?
bool detectIndent; // should we try to autodetect the indent?
bool eatLeadingWhitespace; // should we continue eating this delicious indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote) (0 for none)
bool eatLeadingWhitespace; // should we continue eating this delicious
// indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote)
// (0 for none)
FOLD fold; // how do we fold line ends?
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very end)
// Note: strip means kill all, clip means keep at most one, keep means keep all
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very
// end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very
// end)
// Note: strip means kill all, clip means keep at most one, keep means keep
// all
ACTION onDocIndicator; // what do we do if we see a document indicator?
ACTION onTabInIndentation; // what do we do if we see a tab where we should be seeing indentation spaces
ACTION onTabInIndentation; // what do we do if we see a tab where we should
// be seeing indentation spaces
// output:
bool leadingSpaces;
};
};
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info);
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info);
}
#endif // SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -3,82 +3,77 @@
#include "exp.h"
#include "yaml-cpp/exceptions.h"
namespace YAML
{
const std::string ScanVerbatimTag(Stream& INPUT)
{
namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT) {
std::string tag;
// eat the start character
INPUT.get();
while(INPUT) {
if(INPUT.peek() == Keys::VerbatimTagEnd) {
while (INPUT) {
if (INPUT.peek() == Keys::VerbatimTagEnd) {
// eat the end character
INPUT.get();
return tag;
}
int n = Exp::URI().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
}
}
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle)
{
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
std::string tag;
canBeHandle = true;
Mark firstNonWordChar;
while(INPUT) {
if(INPUT.peek() == Keys::Tag) {
if(!canBeHandle)
while (INPUT) {
if (INPUT.peek() == Keys::Tag) {
if (!canBeHandle)
throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
break;
}
int n = 0;
if(canBeHandle) {
if (canBeHandle) {
n = Exp::Word().Match(INPUT);
if(n <= 0) {
if (n <= 0) {
canBeHandle = false;
firstNonWordChar = INPUT.mark();
}
}
if(!canBeHandle)
if (!canBeHandle)
n = Exp::Tag().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
return tag;
}
}
const std::string ScanTagSuffix(Stream& INPUT)
{
const std::string ScanTagSuffix(Stream& INPUT) {
std::string tag;
while(INPUT) {
while (INPUT) {
int n = Exp::Tag().Match(INPUT);
if(n <= 0)
if (n <= 0)
break;
tag += INPUT.get(n);
}
if(tag.empty())
if (tag.empty())
throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
return tag;
}
}
}
#ifndef SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include "stream.h"
namespace YAML
{
const std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagSuffix(Stream& INPUT);
namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagSuffix(Stream& INPUT);
}
#endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -7,17 +7,15 @@
#include "tag.h"
#include <sstream>
namespace YAML
{
///////////////////////////////////////////////////////////////////////
// Specialization for scanning specific tokens
// Directive
// . Note: no semantic checking is done here (that's for the parser to do)
void Scanner::ScanDirective()
{
namespace YAML {
///////////////////////////////////////////////////////////////////////
// Specialization for scanning specific tokens
// Directive
// . Note: no semantic checking is done here (that's for the parser to do)
void Scanner::ScanDirective() {
std::string name;
std::vector <std::string> params;
std::vector<std::string> params;
// pop indents and simple keys
PopAllIndents();
......@@ -31,33 +29,32 @@ namespace YAML
INPUT.eat(1);
// read name
while(INPUT && !Exp::BlankOrBreak().Matches(INPUT))
while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
token.value += INPUT.get();
// read parameters
while(1) {
while (1) {
// first get rid of whitespace
while(Exp::Blank().Matches(INPUT))
while (Exp::Blank().Matches(INPUT))
INPUT.eat(1);
// break on newline or comment
if(!INPUT || Exp::Break().Matches(INPUT) || Exp::Comment().Matches(INPUT))
if (!INPUT || Exp::Break().Matches(INPUT) || Exp::Comment().Matches(INPUT))
break;
// now read parameter
std::string param;
while(INPUT && !Exp::BlankOrBreak().Matches(INPUT))
while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
param += INPUT.get();
token.params.push_back(param);
}
m_tokens.push(token);
}
}
// DocStart
void Scanner::ScanDocStart()
{
// DocStart
void Scanner::ScanDocStart() {
PopAllIndents();
PopAllSimpleKeys();
m_simpleKeyAllowed = false;
......@@ -67,11 +64,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(3);
m_tokens.push(Token(Token::DOC_START, mark));
}
}
// DocEnd
void Scanner::ScanDocEnd()
{
// DocEnd
void Scanner::ScanDocEnd() {
PopAllIndents();
PopAllSimpleKeys();
m_simpleKeyAllowed = false;
......@@ -81,11 +77,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(3);
m_tokens.push(Token(Token::DOC_END, mark));
}
}
// FlowStart
void Scanner::ScanFlowStart()
{
// FlowStart
void Scanner::ScanFlowStart() {
// flows can be simple keys
InsertPotentialSimpleKey();
m_simpleKeyAllowed = true;
......@@ -96,21 +91,21 @@ namespace YAML
char ch = INPUT.get();
FLOW_MARKER flowType = (ch == Keys::FlowSeqStart ? FLOW_SEQ : FLOW_MAP);
m_flows.push(flowType);
Token::TYPE type = (flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START);
Token::TYPE type =
(flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START);
m_tokens.push(Token(type, mark));
}
}
// FlowEnd
void Scanner::ScanFlowEnd()
{
if(InBlockContext())
// FlowEnd
void Scanner::ScanFlowEnd() {
if (InBlockContext())
throw ParserException(INPUT.mark(), ErrorMsg::FLOW_END);
// we might have a solo entry in the flow context
if(InFlowContext()) {
if(m_flows.top() == FLOW_MAP && VerifySimpleKey())
if (InFlowContext()) {
if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
m_tokens.push(Token(Token::VALUE, INPUT.mark()));
else if(m_flows.top() == FLOW_SEQ)
else if (m_flows.top() == FLOW_SEQ)
InvalidateSimpleKey();
}
......@@ -123,22 +118,21 @@ namespace YAML
// check that it matches the start
FLOW_MARKER flowType = (ch == Keys::FlowSeqEnd ? FLOW_SEQ : FLOW_MAP);
if(m_flows.top() != flowType)
if (m_flows.top() != flowType)
throw ParserException(mark, ErrorMsg::FLOW_END);
m_flows.pop();
Token::TYPE type = (flowType ? Token::FLOW_SEQ_END : Token::FLOW_MAP_END);
m_tokens.push(Token(type, mark));
}
}
// FlowEntry
void Scanner::ScanFlowEntry()
{
// FlowEntry
void Scanner::ScanFlowEntry() {
// we might have a solo entry in the flow context
if(InFlowContext()) {
if(m_flows.top() == FLOW_MAP && VerifySimpleKey())
if (InFlowContext()) {
if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
m_tokens.push(Token(Token::VALUE, INPUT.mark()));
else if(m_flows.top() == FLOW_SEQ)
else if (m_flows.top() == FLOW_SEQ)
InvalidateSimpleKey();
}
......@@ -149,17 +143,16 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::FLOW_ENTRY, mark));
}
}
// BlockEntry
void Scanner::ScanBlockEntry()
{
// BlockEntry
void Scanner::ScanBlockEntry() {
// we better be in the block context!
if(InFlowContext())
if (InFlowContext())
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
// can we put it here?
if(!m_simpleKeyAllowed)
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
PushIndentTo(INPUT.column(), IndentMarker::SEQ);
......@@ -170,14 +163,13 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::BLOCK_ENTRY, mark));
}
}
// Key
void Scanner::ScanKey()
{
// Key
void Scanner::ScanKey() {
// handle keys diffently in the block context (and manage indents)
if(InBlockContext()) {
if(!m_simpleKeyAllowed)
if (InBlockContext()) {
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::MAP_KEY);
PushIndentTo(INPUT.column(), IndentMarker::MAP);
......@@ -190,22 +182,22 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::KEY, mark));
}
}
// Value
void Scanner::ScanValue()
{
// Value
void Scanner::ScanValue() {
// and check that simple key
bool isSimpleKey = VerifySimpleKey();
m_canBeJSONFlow = false;
if(isSimpleKey) {
// can't follow a simple key with another simple key (dunno why, though - it seems fine)
if (isSimpleKey) {
// can't follow a simple key with another simple key (dunno why, though - it
// seems fine)
m_simpleKeyAllowed = false;
} else {
// handle values diffently in the block context (and manage indents)
if(InBlockContext()) {
if(!m_simpleKeyAllowed)
if (InBlockContext()) {
if (!m_simpleKeyAllowed)
throw ParserException(INPUT.mark(), ErrorMsg::MAP_VALUE);
PushIndentTo(INPUT.column(), IndentMarker::MAP);
......@@ -219,11 +211,10 @@ namespace YAML
Mark mark = INPUT.mark();
INPUT.eat(1);
m_tokens.push(Token(Token::VALUE, mark));
}
}
// AnchorOrAlias
void Scanner::ScanAnchorOrAlias()
{
// AnchorOrAlias
void Scanner::ScanAnchorOrAlias() {
bool alias;
std::string name;
......@@ -238,26 +229,27 @@ namespace YAML
alias = (indicator == Keys::Alias);
// now eat the content
while(INPUT && Exp::Anchor().Matches(INPUT))
while (INPUT && Exp::Anchor().Matches(INPUT))
name += INPUT.get();
// we need to have read SOMETHING!
if(name.empty())
throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND : ErrorMsg::ANCHOR_NOT_FOUND);
if (name.empty())
throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND
: ErrorMsg::ANCHOR_NOT_FOUND);
// and needs to end correctly
if(INPUT && !Exp::AnchorEnd().Matches(INPUT))
throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS : ErrorMsg::CHAR_IN_ANCHOR);
if (INPUT && !Exp::AnchorEnd().Matches(INPUT))
throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS
: ErrorMsg::CHAR_IN_ANCHOR);
// and we're done
Token token(alias ? Token::ALIAS : Token::ANCHOR, mark);
token.value = name;
m_tokens.push(token);
}
}
// Tag
void Scanner::ScanTag()
{
// Tag
void Scanner::ScanTag() {
// insert a potential simple key
InsertPotentialSimpleKey();
m_simpleKeyAllowed = false;
......@@ -268,7 +260,7 @@ namespace YAML
// eat the indicator
INPUT.get();
if(INPUT && INPUT.peek() == Keys::VerbatimTagStart){
if (INPUT && INPUT.peek() == Keys::VerbatimTagStart) {
std::string tag = ScanVerbatimTag(INPUT);
token.value = tag;
......@@ -276,15 +268,15 @@ namespace YAML
} else {
bool canBeHandle;
token.value = ScanTagHandle(INPUT, canBeHandle);
if(!canBeHandle && token.value.empty())
if (!canBeHandle && token.value.empty())
token.data = Tag::NON_SPECIFIC;
else if(token.value.empty())
else if (token.value.empty())
token.data = Tag::SECONDARY_HANDLE;
else
token.data = Tag::PRIMARY_HANDLE;
// is there a suffix?
if(canBeHandle && INPUT.peek() == Keys::Tag) {
if (canBeHandle && INPUT.peek() == Keys::Tag) {
// eat the indicator
INPUT.get();
token.params.push_back(ScanTagSuffix(INPUT));
......@@ -293,16 +285,16 @@ namespace YAML
}
m_tokens.push(token);
}
}
// PlainScalar
void Scanner::ScanPlainScalar()
{
// PlainScalar
void Scanner::ScanPlainScalar() {
std::string scalar;
// set up the scanning parameters
ScanScalarParams params;
params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) || (Exp::BlankOrBreak() + Exp::Comment());
params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) ||
(Exp::BlankOrBreak() + Exp::Comment());
params.eatEnd = false;
params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1);
params.fold = FOLD_FLOW;
......@@ -323,20 +315,20 @@ namespace YAML
m_canBeJSONFlow = false;
// finally, check and see if we ended on an illegal character
//if(Exp::IllegalCharInScalar.Matches(INPUT))
// if(Exp::IllegalCharInScalar.Matches(INPUT))
// throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR);
Token token(Token::PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
// QuotedScalar
void Scanner::ScanQuotedScalar()
{
// QuotedScalar
void Scanner::ScanQuotedScalar() {
std::string scalar;
// peek at single or double quote (don't eat because we need to preserve (for the time being) the input position)
// peek at single or double quote (don't eat because we need to preserve (for
// the time being) the input position)
char quote = INPUT.peek();
bool single = (quote == '\'');
......@@ -368,14 +360,14 @@ namespace YAML
Token token(Token::NON_PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
// BlockScalarToken
// . These need a little extra processing beforehand.
// . We need to scan the line where the indicator is (this doesn't count as part of the scalar),
// and then we need to figure out what level of indentation we'll be using.
void Scanner::ScanBlockScalar()
{
// BlockScalarToken
// . These need a little extra processing beforehand.
// . We need to scan the line where the indicator is (this doesn't count as part
// of the scalar),
// and then we need to figure out what level of indentation we'll be using.
void Scanner::ScanBlockScalar() {
std::string scalar;
ScanScalarParams params;
......@@ -390,14 +382,14 @@ namespace YAML
// eat chomping/indentation indicators
params.chomp = CLIP;
int n = Exp::Chomp().Match(INPUT);
for(int i=0;i<n;i++) {
for (int i = 0; i < n; i++) {
char ch = INPUT.get();
if(ch == '+')
if (ch == '+')
params.chomp = KEEP;
else if(ch == '-')
else if (ch == '-')
params.chomp = STRIP;
else if(Exp::Digit().Matches(ch)) {
if(ch == '0')
else if (Exp::Digit().Matches(ch)) {
if (ch == '0')
throw ParserException(INPUT.mark(), ErrorMsg::ZERO_INDENT_IN_BLOCK);
params.indent = ch - '0';
......@@ -406,20 +398,20 @@ namespace YAML
}
// now eat whitespace
while(Exp::Blank().Matches(INPUT))
while (Exp::Blank().Matches(INPUT))
INPUT.eat(1);
// and comments to the end of the line
if(Exp::Comment().Matches(INPUT))
while(INPUT && !Exp::Break().Matches(INPUT))
if (Exp::Comment().Matches(INPUT))
while (INPUT && !Exp::Break().Matches(INPUT))
INPUT.eat(1);
// if it's not a line break, then we ran into a bad character inline
if(INPUT && !Exp::Break().Matches(INPUT))
if (INPUT && !Exp::Break().Matches(INPUT))
throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_BLOCK);
// set the initial indentation
if(GetTopIndent() >= 0)
if (GetTopIndent() >= 0)
params.indent += GetTopIndent();
params.eatLeadingWhitespace = false;
......@@ -428,12 +420,13 @@ namespace YAML
scalar = ScanScalar(INPUT, params);
// simple keys always ok after block scalars (since we're gonna start a new line anyways)
// simple keys always ok after block scalars (since we're gonna start a new
// line anyways)
m_simpleKeyAllowed = true;
m_canBeJSONFlow = false;
Token token(Token::NON_PLAIN_SCALAR, mark);
token.value = scalar;
m_tokens.push(token);
}
}
}
#ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <memory>
#include <vector>
#include "yaml-cpp/noncopyable.h"
namespace YAML
{
class SettingChangeBase;
namespace YAML {
class SettingChangeBase;
template <typename T>
class Setting
{
template <typename T>
class Setting {
public:
Setting(): m_value() {}
Setting() : m_value() {}
const T get() const { return m_value; }
std::auto_ptr <SettingChangeBase> set(const T& value);
void restore(const Setting<T>& oldSetting) {
m_value = oldSetting.get();
}
std::auto_ptr<SettingChangeBase> set(const T& value);
void restore(const Setting<T>& oldSetting) { m_value = oldSetting.get(); }
private:
T m_value;
};
};
class SettingChangeBase
{
class SettingChangeBase {
public:
virtual ~SettingChangeBase() {}
virtual void pop() = 0;
};
};
template <typename T>
class SettingChange: public SettingChangeBase
{
template <typename T>
class SettingChange : public SettingChangeBase {
public:
SettingChange(Setting<T> *pSetting): m_pCurSetting(pSetting) {
SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) {
// copy old setting to save its state
m_oldSetting = *pSetting;
}
virtual void pop() {
m_pCurSetting->restore(m_oldSetting);
}
virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
private:
Setting<T> *m_pCurSetting;
Setting<T>* m_pCurSetting;
Setting<T> m_oldSetting;
};
};
template <typename T>
inline std::auto_ptr <SettingChangeBase> Setting<T>::set(const T& value) {
std::auto_ptr <SettingChangeBase> pChange(new SettingChange<T> (this));
template <typename T>
inline std::auto_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
std::auto_ptr<SettingChangeBase> pChange(new SettingChange<T>(this));
m_value = value;
return pChange;
}
}
class SettingChanges: private noncopyable
{
class SettingChanges : private noncopyable {
public:
SettingChanges() {}
~SettingChanges() { clear(); }
......@@ -71,23 +63,25 @@ namespace YAML
void clear() {
restore();
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it)
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
delete *it;
m_settingChanges.clear();
}
void restore() {
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it)
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
(*it)->pop();
}
void push(std::auto_ptr <SettingChangeBase> pSettingChange) {
void push(std::auto_ptr<SettingChangeBase> pSettingChange) {
m_settingChanges.push_back(pSettingChange.release());
}
// like std::auto_ptr - assignment is transfer of ownership
SettingChanges& operator = (SettingChanges& rhs) {
if(this == &rhs)
SettingChanges& operator=(SettingChanges& rhs) {
if (this == &rhs)
return *this;
clear();
......@@ -97,9 +91,9 @@ namespace YAML
}
private:
typedef std::vector <SettingChangeBase *> setting_changes;
typedef std::vector<SettingChangeBase*> setting_changes;
setting_changes m_settingChanges;
};
};
}
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -3,71 +3,64 @@
#include "yaml-cpp/exceptions.h"
#include "exp.h"
namespace YAML
{
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0)
{
}
namespace YAML {
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {}
void Scanner::SimpleKey::Validate()
{
void Scanner::SimpleKey::Validate() {
// Note: pIndent will *not* be garbage here;
// we "garbage collect" them so we can
// always refer to them
if(pIndent)
if (pIndent)
pIndent->status = IndentMarker::VALID;
if(pMapStart)
if (pMapStart)
pMapStart->status = Token::VALID;
if(pKey)
if (pKey)
pKey->status = Token::VALID;
}
}
void Scanner::SimpleKey::Invalidate()
{
if(pIndent)
void Scanner::SimpleKey::Invalidate() {
if (pIndent)
pIndent->status = IndentMarker::INVALID;
if(pMapStart)
if (pMapStart)
pMapStart->status = Token::INVALID;
if(pKey)
if (pKey)
pKey->status = Token::INVALID;
}
}
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const
{
if(!m_simpleKeyAllowed)
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const {
if (!m_simpleKeyAllowed)
return false;
return !ExistsActiveSimpleKey();
}
}
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow start token)
bool Scanner::ExistsActiveSimpleKey() const
{
if(m_simpleKeys.empty())
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow
// start token)
bool Scanner::ExistsActiveSimpleKey() const {
if (m_simpleKeys.empty())
return false;
const SimpleKey& key = m_simpleKeys.top();
return key.flowLevel == GetFlowLevel();
}
}
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey()
{
if(!CanInsertPotentialSimpleKey())
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey() {
if (!CanInsertPotentialSimpleKey())
return;
SimpleKey key(INPUT.mark(), GetFlowLevel());
// first add a map start, if necessary
if(InBlockContext()) {
if (InBlockContext()) {
key.pIndent = PushIndentTo(INPUT.column(), IndentMarker::MAP);
if(key.pIndent) {
if (key.pIndent) {
key.pIndent->status = IndentMarker::UNKNOWN;
key.pMapStart = key.pIndent->pStartToken;
key.pMapStart->status = Token::UNVERIFIED;
......@@ -80,37 +73,35 @@ namespace YAML
key.pKey->status = Token::UNVERIFIED;
m_simpleKeys.push(key);
}
}
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey()
{
if(m_simpleKeys.empty())
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey() {
if (m_simpleKeys.empty())
return;
// grab top key
SimpleKey& key = m_simpleKeys.top();
if(key.flowLevel != GetFlowLevel())
if (key.flowLevel != GetFlowLevel())
return;
key.Invalidate();
m_simpleKeys.pop();
}
}
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey()
{
if(m_simpleKeys.empty())
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey() {
if (m_simpleKeys.empty())
return false;
// grab top key
SimpleKey key = m_simpleKeys.top();
// only validate if we're in the correct flow level
if(key.flowLevel != GetFlowLevel())
if (key.flowLevel != GetFlowLevel())
return false;
m_simpleKeys.pop();
......@@ -118,22 +109,20 @@ namespace YAML
bool isValid = true;
// needs to be less than 1024 characters and inline
if(INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
if (INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
isValid = false;
// invalidate key
if(isValid)
if (isValid)
key.Validate();
else
key.Invalidate();
return isValid;
}
}
void Scanner::PopAllSimpleKeys()
{
while(!m_simpleKeys.empty())
void Scanner::PopAllSimpleKeys() {
while (!m_simpleKeys.empty())
m_simpleKeys.pop();
}
}
}
......@@ -10,28 +10,26 @@
#include <cstdio>
#include <algorithm>
namespace YAML
{
SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives): m_scanner(scanner), m_directives(directives), m_pCollectionStack(new CollectionStack), m_curAnchor(0)
{
}
SingleDocParser::~SingleDocParser()
{
}
// HandleDocument
// . Handles the next document
// . Throws a ParserException on error.
void SingleDocParser::HandleDocument(EventHandler& eventHandler)
{
namespace YAML {
SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives)
: m_scanner(scanner),
m_directives(directives),
m_pCollectionStack(new CollectionStack),
m_curAnchor(0) {}
SingleDocParser::~SingleDocParser() {}
// HandleDocument
// . Handles the next document
// . Throws a ParserException on error.
void SingleDocParser::HandleDocument(EventHandler& eventHandler) {
assert(!m_scanner.empty()); // guaranteed that there are tokens
assert(!m_curAnchor);
eventHandler.OnDocumentStart(m_scanner.peek().mark);
// eat doc start
if(m_scanner.peek().type == Token::DOC_START)
if (m_scanner.peek().type == Token::DOC_START)
m_scanner.pop();
// recurse!
......@@ -40,14 +38,13 @@ namespace YAML
eventHandler.OnDocumentEnd();
// and finally eat any doc ends we see
while(!m_scanner.empty() && m_scanner.peek().type == Token::DOC_END)
while (!m_scanner.empty() && m_scanner.peek().type == Token::DOC_END)
m_scanner.pop();
}
}
void SingleDocParser::HandleNode(EventHandler& eventHandler)
{
void SingleDocParser::HandleNode(EventHandler& eventHandler) {
// an empty node *is* a possibility
if(m_scanner.empty()) {
if (m_scanner.empty()) {
eventHandler.OnNull(m_scanner.mark(), NullAnchor);
return;
}
......@@ -56,7 +53,7 @@ namespace YAML
Mark mark = m_scanner.peek().mark;
// special case: a value node by itself must be a map, with no header
if(m_scanner.peek().type == Token::VALUE) {
if (m_scanner.peek().type == Token::VALUE) {
eventHandler.OnMapStart(mark, "?", NullAnchor);
HandleMap(eventHandler);
eventHandler.OnMapEnd();
......@@ -64,7 +61,7 @@ namespace YAML
}
// special case: an alias node
if(m_scanner.peek().type == Token::ALIAS) {
if (m_scanner.peek().type == Token::ALIAS) {
eventHandler.OnAlias(mark, LookupAnchor(mark, m_scanner.peek().value));
m_scanner.pop();
return;
......@@ -76,18 +73,18 @@ namespace YAML
const Token& token = m_scanner.peek();
if(token.type == Token::PLAIN_SCALAR && token.value == "null") {
if (token.type == Token::PLAIN_SCALAR && token.value == "null") {
eventHandler.OnNull(mark, anchor);
m_scanner.pop();
return;
}
// add non-specific tags
if(tag.empty())
if (tag.empty())
tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?");
// now split based on what kind of node we should be
switch(token.type) {
switch (token.type) {
case Token::PLAIN_SCALAR:
case Token::NON_PLAIN_SCALAR:
eventHandler.OnScalar(mark, tag, anchor, token.value);
......@@ -107,7 +104,8 @@ namespace YAML
return;
case Token::KEY:
// compact maps can only go in a flow sequence
if(m_pCollectionStack->GetCurCollectionType() == CollectionType::FlowSeq) {
if (m_pCollectionStack->GetCurCollectionType() ==
CollectionType::FlowSeq) {
eventHandler.OnMapStart(mark, tag, anchor);
HandleMap(eventHandler);
eventHandler.OnMapEnd();
......@@ -118,44 +116,48 @@ namespace YAML
break;
}
if(tag == "?")
if (tag == "?")
eventHandler.OnNull(mark, anchor);
else
eventHandler.OnScalar(mark, tag, anchor, "");
}
}
void SingleDocParser::HandleSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleSequence(EventHandler& eventHandler) {
// split based on start token
switch(m_scanner.peek().type) {
case Token::BLOCK_SEQ_START: HandleBlockSequence(eventHandler); break;
case Token::FLOW_SEQ_START: HandleFlowSequence(eventHandler); break;
default: break;
}
switch (m_scanner.peek().type) {
case Token::BLOCK_SEQ_START:
HandleBlockSequence(eventHandler);
break;
case Token::FLOW_SEQ_START:
HandleFlowSequence(eventHandler);
break;
default:
break;
}
}
void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::BlockSeq);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
Token token = m_scanner.peek();
if(token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
if (token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ);
m_scanner.pop();
if(token.type == Token::BLOCK_SEQ_END)
if (token.type == Token::BLOCK_SEQ_END)
break;
// check for null
if(!m_scanner.empty()) {
if (!m_scanner.empty()) {
const Token& token = m_scanner.peek();
if(token.type == Token::BLOCK_ENTRY || token.type == Token::BLOCK_SEQ_END) {
if (token.type == Token::BLOCK_ENTRY ||
token.type == Token::BLOCK_SEQ_END) {
eventHandler.OnNull(token.mark, NullAnchor);
continue;
}
......@@ -165,20 +167,19 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::BlockSeq);
}
}
void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler)
{
void SingleDocParser::HandleFlowSequence(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::FlowSeq);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
// first check for end
if(m_scanner.peek().type == Token::FLOW_SEQ_END) {
if (m_scanner.peek().type == Token::FLOW_SEQ_END) {
m_scanner.pop();
break;
}
......@@ -186,53 +187,62 @@ namespace YAML
// then read the node
HandleNode(eventHandler);
if(m_scanner.empty())
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a sequence end, which we ignore - but
// if it's neither, then it's a bad node)
Token& token = m_scanner.peek();
if(token.type == Token::FLOW_ENTRY)
if (token.type == Token::FLOW_ENTRY)
m_scanner.pop();
else if(token.type != Token::FLOW_SEQ_END)
else if (token.type != Token::FLOW_SEQ_END)
throw ParserException(token.mark, ErrorMsg::END_OF_SEQ_FLOW);
}
m_pCollectionStack->PopCollectionType(CollectionType::FlowSeq);
}
}
void SingleDocParser::HandleMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleMap(EventHandler& eventHandler) {
// split based on start token
switch(m_scanner.peek().type) {
case Token::BLOCK_MAP_START: HandleBlockMap(eventHandler); break;
case Token::FLOW_MAP_START: HandleFlowMap(eventHandler); break;
case Token::KEY: HandleCompactMap(eventHandler); break;
case Token::VALUE: HandleCompactMapWithNoKey(eventHandler); break;
default: break;
}
switch (m_scanner.peek().type) {
case Token::BLOCK_MAP_START:
HandleBlockMap(eventHandler);
break;
case Token::FLOW_MAP_START:
HandleFlowMap(eventHandler);
break;
case Token::KEY:
HandleCompactMap(eventHandler);
break;
case Token::VALUE:
HandleCompactMapWithNoKey(eventHandler);
break;
default:
break;
}
}
void SingleDocParser::HandleBlockMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleBlockMap(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::BlockMap);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP);
Token token = m_scanner.peek();
if(token.type != Token::KEY && token.type != Token::VALUE && token.type != Token::BLOCK_MAP_END)
if (token.type != Token::KEY && token.type != Token::VALUE &&
token.type != Token::BLOCK_MAP_END)
throw ParserException(token.mark, ErrorMsg::END_OF_MAP);
if(token.type == Token::BLOCK_MAP_END) {
if (token.type == Token::BLOCK_MAP_END) {
m_scanner.pop();
break;
}
// grab key (if non-null)
if(token.type == Token::KEY) {
if (token.type == Token::KEY) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
......@@ -240,7 +250,7 @@ namespace YAML
}
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
......@@ -249,28 +259,27 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::BlockMap);
}
}
void SingleDocParser::HandleFlowMap(EventHandler& eventHandler)
{
void SingleDocParser::HandleFlowMap(EventHandler& eventHandler) {
// eat start token
m_scanner.pop();
m_pCollectionStack->PushCollectionType(CollectionType::FlowMap);
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
Token& token = m_scanner.peek();
const Mark mark = token.mark;
// first check for end
if(token.type == Token::FLOW_MAP_END) {
if (token.type == Token::FLOW_MAP_END) {
m_scanner.pop();
break;
}
// grab key (if non-null)
if(token.type == Token::KEY) {
if (token.type == Token::KEY) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
......@@ -278,30 +287,30 @@ namespace YAML
}
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
eventHandler.OnNull(mark, NullAnchor);
}
if(m_scanner.empty())
if (m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a map end, which we ignore - but if
// it's neither, then it's a bad node)
Token& nextToken = m_scanner.peek();
if(nextToken.type == Token::FLOW_ENTRY)
if (nextToken.type == Token::FLOW_ENTRY)
m_scanner.pop();
else if(nextToken.type != Token::FLOW_MAP_END)
else if (nextToken.type != Token::FLOW_MAP_END)
throw ParserException(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW);
}
m_pCollectionStack->PopCollectionType(CollectionType::FlowMap);
}
}
// . Single "key: value" pair in a flow sequence
void SingleDocParser::HandleCompactMap(EventHandler& eventHandler)
{
// . Single "key: value" pair in a flow sequence
void SingleDocParser::HandleCompactMap(EventHandler& eventHandler) {
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
// grab key
......@@ -310,7 +319,7 @@ namespace YAML
HandleNode(eventHandler);
// now grab value (optional)
if(!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
if (!m_scanner.empty() && m_scanner.peek().type == Token::VALUE) {
m_scanner.pop();
HandleNode(eventHandler);
} else {
......@@ -318,11 +327,10 @@ namespace YAML
}
m_pCollectionStack->PopCollectionType(CollectionType::CompactMap);
}
}
// . Single ": value" pair in a flow sequence
void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler)
{
// . Single ": value" pair in a flow sequence
void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler) {
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
// null key
......@@ -333,62 +341,63 @@ namespace YAML
HandleNode(eventHandler);
m_pCollectionStack->PopCollectionType(CollectionType::CompactMap);
}
}
// ParseProperties
// . Grabs any tag or anchor tokens and deals with them.
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor)
{
// ParseProperties
// . Grabs any tag or anchor tokens and deals with them.
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
tag.clear();
anchor = NullAnchor;
while(1) {
if(m_scanner.empty())
while (1) {
if (m_scanner.empty())
return;
switch(m_scanner.peek().type) {
case Token::TAG: ParseTag(tag); break;
case Token::ANCHOR: ParseAnchor(anchor); break;
default: return;
}
switch (m_scanner.peek().type) {
case Token::TAG:
ParseTag(tag);
break;
case Token::ANCHOR:
ParseAnchor(anchor);
break;
default:
return;
}
}
}
void SingleDocParser::ParseTag(std::string& tag)
{
void SingleDocParser::ParseTag(std::string& tag) {
Token& token = m_scanner.peek();
if(!tag.empty())
if (!tag.empty())
throw ParserException(token.mark, ErrorMsg::MULTIPLE_TAGS);
Tag tagInfo(token);
tag = tagInfo.Translate(m_directives);
m_scanner.pop();
}
}
void SingleDocParser::ParseAnchor(anchor_t& anchor)
{
void SingleDocParser::ParseAnchor(anchor_t& anchor) {
Token& token = m_scanner.peek();
if(anchor)
if (anchor)
throw ParserException(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
anchor = RegisterAnchor(token.value);
m_scanner.pop();
}
}
anchor_t SingleDocParser::RegisterAnchor(const std::string& name)
{
if(name.empty())
anchor_t SingleDocParser::RegisterAnchor(const std::string& name) {
if (name.empty())
return NullAnchor;
return m_anchors[name] = ++m_curAnchor;
}
}
anchor_t SingleDocParser::LookupAnchor(const Mark& mark, const std::string& name) const
{
anchor_t SingleDocParser::LookupAnchor(const Mark& mark,
const std::string& name) const {
Anchors::const_iterator it = m_anchors.find(name);
if(it == m_anchors.end())
if (it == m_anchors.end())
throw ParserException(mark, ErrorMsg::UNKNOWN_ANCHOR);
return it->second;
}
}
}
#ifndef SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/anchor.h"
#include "yaml-cpp/noncopyable.h"
#include <string>
#include <map>
#include <memory>
namespace YAML
{
struct Directives;
struct Mark;
struct Token;
class CollectionStack;
class EventHandler;
class Node;
class Scanner;
namespace YAML {
struct Directives;
struct Mark;
struct Token;
class CollectionStack;
class EventHandler;
class Node;
class Scanner;
class SingleDocParser: private noncopyable
{
class SingleDocParser : private noncopyable {
public:
SingleDocParser(Scanner& scanner, const Directives& directives);
~SingleDocParser();
......@@ -59,7 +58,7 @@ namespace YAML
Anchors m_anchors;
anchor_t m_curAnchor;
};
};
}
#endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -6,14 +6,13 @@
#define YAML_PREFETCH_SIZE 2048
#endif
#define S_ARRAY_SIZE( A ) (sizeof(A)/sizeof(*(A)))
#define S_ARRAY_END( A ) ((A) + S_ARRAY_SIZE(A))
#define S_ARRAY_SIZE(A) (sizeof(A) / sizeof(*(A)))
#define S_ARRAY_END(A) ((A) + S_ARRAY_SIZE(A))
#define CP_REPLACEMENT_CHARACTER (0xFFFD)
namespace YAML
{
enum UtfIntroState {
namespace YAML {
enum UtfIntroState {
uis_start,
uis_utfbe_b1,
uis_utf32be_b2,
......@@ -33,9 +32,9 @@ namespace YAML
uis_utf8_bom2,
uis_utf8,
uis_error
};
};
enum UtfIntroCharType {
enum UtfIntroCharType {
uict00,
uictBB,
uictBF,
......@@ -45,53 +44,70 @@ namespace YAML
uictAscii,
uictOther,
uictMax
};
static bool s_introFinalState[] = {
false, //uis_start
false, //uis_utfbe_b1
false, //uis_utf32be_b2
false, //uis_utf32be_bom3
true, //uis_utf32be
true, //uis_utf16be
false, //uis_utf16be_bom1
false, //uis_utfle_bom1
false, //uis_utf16le_bom2
false, //uis_utf32le_bom3
true, //uis_utf16le
true, //uis_utf32le
false, //uis_utf8_imp
false, //uis_utf16le_imp
false, //uis_utf32le_imp3
false, //uis_utf8_bom1
false, //uis_utf8_bom2
true, //uis_utf8
true, //uis_error
};
static UtfIntroState s_introTransitions[][uictMax] = {
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
{uis_utfbe_b1, uis_utf8, uis_utf8, uis_utf8_bom1, uis_utf16be_bom1, uis_utfle_bom1, uis_utf8_imp, uis_utf8},
{uis_utf32be_b2, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16be, uis_utf8},
{uis_utf32be, uis_utf8, uis_utf8, uis_utf8, uis_utf32be_bom3, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf32be, uis_utf8, uis_utf8},
{uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be},
{uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16be, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf16le_bom2, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_bom3, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le},
{uis_utf16le_imp, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_imp3, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf8, uis_utf8_bom2, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8, uis_utf8},
};
static char s_introUngetCount[][uictMax] = {
};
static bool s_introFinalState[] = {false, // uis_start
false, // uis_utfbe_b1
false, // uis_utf32be_b2
false, // uis_utf32be_bom3
true, // uis_utf32be
true, // uis_utf16be
false, // uis_utf16be_bom1
false, // uis_utfle_bom1
false, // uis_utf16le_bom2
false, // uis_utf32le_bom3
true, // uis_utf16le
true, // uis_utf32le
false, // uis_utf8_imp
false, // uis_utf16le_imp
false, // uis_utf32le_imp3
false, // uis_utf8_bom1
false, // uis_utf8_bom2
true, // uis_utf8
true, // uis_error
};
static UtfIntroState s_introTransitions[][uictMax] = {
// uict00, uictBB, uictBF, uictEF,
// uictFE, uictFF, uictAscii, uictOther
{uis_utfbe_b1, uis_utf8, uis_utf8, uis_utf8_bom1,
uis_utf16be_bom1, uis_utfle_bom1, uis_utf8_imp, uis_utf8},
{uis_utf32be_b2, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf16be, uis_utf8},
{uis_utf32be, uis_utf8, uis_utf8, uis_utf8,
uis_utf32be_bom3, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf32be, uis_utf8, uis_utf8},
{uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be,
uis_utf32be, uis_utf32be, uis_utf32be, uis_utf32be},
{uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be,
uis_utf16be, uis_utf16be, uis_utf16be, uis_utf16be},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf16be, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf16le_bom2, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_bom3, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le,
uis_utf32le, uis_utf32le, uis_utf32le, uis_utf32le},
{uis_utf16le_imp, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf32le_imp3, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf32le, uis_utf16le, uis_utf16le, uis_utf16le,
uis_utf16le, uis_utf16le, uis_utf16le, uis_utf16le},
{uis_utf8, uis_utf8_bom2, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8},
{uis_utf8, uis_utf8, uis_utf8, uis_utf8,
uis_utf8, uis_utf8, uis_utf8, uis_utf8}, };
static char s_introUngetCount[][uictMax] = {
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
{0, 1, 1, 0, 0, 0, 0, 1},
{0, 2, 2, 2, 2, 2, 2, 2},
......@@ -110,22 +126,26 @@ namespace YAML
{4, 4, 4, 4, 4, 4, 4, 4},
{2, 0, 2, 2, 2, 2, 2, 2},
{3, 3, 0, 3, 3, 3, 3, 3},
{1, 1, 1, 1, 1, 1, 1, 1},
};
{1, 1, 1, 1, 1, 1, 1, 1}, };
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch)
{
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
if (std::istream::traits_type::eof() == ch) {
return uictOther;
}
switch (ch) {
case 0: return uict00;
case 0xBB: return uictBB;
case 0xBF: return uictBF;
case 0xEF: return uictEF;
case 0xFE: return uictFE;
case 0xFF: return uictFF;
case 0:
return uict00;
case 0xBB:
return uictBB;
case 0xBF:
return uictBF;
case 0xEF:
return uictEF;
case 0xFE:
return uictFE;
case 0xFF:
return uictFF;
}
if ((ch > 0) && (ch < 0xFF)) {
......@@ -133,58 +153,48 @@ namespace YAML
}
return uictOther;
}
}
inline char Utf8Adjust(unsigned long ch, unsigned char lead_bits, unsigned char rshift)
{
inline char Utf8Adjust(unsigned long ch, unsigned char lead_bits,
unsigned char rshift) {
const unsigned char header = ((1 << lead_bits) - 1) << (8 - lead_bits);
const unsigned char mask = (0xFF >> (lead_bits + 1));
return static_cast<char>(static_cast<unsigned char>(
header | ((ch >> rshift) & mask)
));
}
return static_cast<char>(
static_cast<unsigned char>(header | ((ch >> rshift) & mask)));
}
inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch)
{
inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) {
// We are not allowed to queue the Stream::eof() codepoint, so
// replace it with CP_REPLACEMENT_CHARACTER
if (static_cast<unsigned long>(Stream::eof()) == ch)
{
if (static_cast<unsigned long>(Stream::eof()) == ch) {
ch = CP_REPLACEMENT_CHARACTER;
}
if (ch < 0x80)
{
if (ch < 0x80) {
q.push_back(Utf8Adjust(ch, 0, 0));
}
else if (ch < 0x800)
{
} else if (ch < 0x800) {
q.push_back(Utf8Adjust(ch, 2, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
else if (ch < 0x10000)
{
} else if (ch < 0x10000) {
q.push_back(Utf8Adjust(ch, 3, 12));
q.push_back(Utf8Adjust(ch, 1, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
else
{
} else {
q.push_back(Utf8Adjust(ch, 4, 18));
q.push_back(Utf8Adjust(ch, 1, 12));
q.push_back(Utf8Adjust(ch, 1, 6));
q.push_back(Utf8Adjust(ch, 1, 0));
}
}
}
Stream::Stream(std::istream& input)
Stream::Stream(std::istream& input)
: m_input(input),
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0)
{
m_nPrefetchedAvailable(0),
m_nPrefetchedUsed(0) {
typedef std::istream::traits_type char_traits;
if(!input)
if (!input)
return;
// Determine (or guess) the character-set by reading the BOM, if any. See
......@@ -192,16 +202,16 @@ namespace YAML
char_traits::int_type intro[4];
int nIntroUsed = 0;
UtfIntroState state = uis_start;
for(; !s_introFinalState[state]; ) {
for (; !s_introFinalState[state];) {
std::istream::int_type ch = input.get();
intro[nIntroUsed++] = ch;
UtfIntroCharType charType = IntroCharTypeOf(ch);
UtfIntroState newState = s_introTransitions[state][charType];
int nUngets = s_introUngetCount[state][charType];
if(nUngets > 0) {
if (nUngets > 0) {
input.clear();
for(; nUngets > 0; --nUngets) {
if(char_traits::eof() != intro[--nIntroUsed])
for (; nUngets > 0; --nUngets) {
if (char_traits::eof() != intro[--nIntroUsed])
input.putback(char_traits::to_char_type(intro[nIntroUsed]));
}
}
......@@ -209,166 +219,163 @@ namespace YAML
}
switch (state) {
case uis_utf8: m_charSet = utf8; break;
case uis_utf16le: m_charSet = utf16le; break;
case uis_utf16be: m_charSet = utf16be; break;
case uis_utf32le: m_charSet = utf32le; break;
case uis_utf32be: m_charSet = utf32be; break;
default: m_charSet = utf8; break;
case uis_utf8:
m_charSet = utf8;
break;
case uis_utf16le:
m_charSet = utf16le;
break;
case uis_utf16be:
m_charSet = utf16be;
break;
case uis_utf32le:
m_charSet = utf32le;
break;
case uis_utf32be:
m_charSet = utf32be;
break;
default:
m_charSet = utf8;
break;
}
ReadAheadTo(0);
}
}
Stream::~Stream()
{
delete[] m_pPrefetched;
}
Stream::~Stream() { delete[] m_pPrefetched; }
char Stream::peek() const
{
if (m_readahead.empty())
{
char Stream::peek() const {
if (m_readahead.empty()) {
return Stream::eof();
}
return m_readahead[0];
}
}
Stream::operator bool() const
{
return m_input.good() || (!m_readahead.empty() && m_readahead[0] != Stream::eof());
}
Stream::operator bool() const {
return m_input.good() ||
(!m_readahead.empty() && m_readahead[0] != Stream::eof());
}
// get
// . Extracts a character from the stream and updates our position
char Stream::get()
{
// get
// . Extracts a character from the stream and updates our position
char Stream::get() {
char ch = peek();
AdvanceCurrent();
m_mark.column++;
if(ch == '\n') {
if (ch == '\n') {
m_mark.column = 0;
m_mark.line++;
}
return ch;
}
}
// get
// . Extracts 'n' characters from the stream and updates our position
std::string Stream::get(int n)
{
// get
// . Extracts 'n' characters from the stream and updates our position
std::string Stream::get(int n) {
std::string ret;
ret.reserve(n);
for(int i=0;i<n;i++)
for (int i = 0; i < n; i++)
ret += get();
return ret;
}
}
// eat
// . Eats 'n' characters and updates our position.
void Stream::eat(int n)
{
for(int i=0;i<n;i++)
// eat
// . Eats 'n' characters and updates our position.
void Stream::eat(int n) {
for (int i = 0; i < n; i++)
get();
}
}
void Stream::AdvanceCurrent()
{
if (!m_readahead.empty())
{
void Stream::AdvanceCurrent() {
if (!m_readahead.empty()) {
m_readahead.pop_front();
m_mark.pos++;
}
ReadAheadTo(0);
}
}
bool Stream::_ReadAheadTo(size_t i) const
{
while (m_input.good() && (m_readahead.size() <= i))
{
switch (m_charSet)
{
case utf8: StreamInUtf8(); break;
case utf16le: StreamInUtf16(); break;
case utf16be: StreamInUtf16(); break;
case utf32le: StreamInUtf32(); break;
case utf32be: StreamInUtf32(); break;
bool Stream::_ReadAheadTo(size_t i) const {
while (m_input.good() && (m_readahead.size() <= i)) {
switch (m_charSet) {
case utf8:
StreamInUtf8();
break;
case utf16le:
StreamInUtf16();
break;
case utf16be:
StreamInUtf16();
break;
case utf32le:
StreamInUtf32();
break;
case utf32be:
StreamInUtf32();
break;
}
}
// signal end of stream
if(!m_input.good())
if (!m_input.good())
m_readahead.push_back(Stream::eof());
return m_readahead.size() > i;
}
}
void Stream::StreamInUtf8() const
{
void Stream::StreamInUtf8() const {
unsigned char b = GetNextByte();
if (m_input.good())
{
if (m_input.good()) {
m_readahead.push_back(b);
}
}
}
void Stream::StreamInUtf16() const
{
void Stream::StreamInUtf16() const {
unsigned long ch = 0;
unsigned char bytes[2];
int nBigEnd = (m_charSet == utf16be) ? 0 : 1;
bytes[0] = GetNextByte();
bytes[1] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
return;
}
ch = (static_cast<unsigned long>(bytes[nBigEnd]) << 8) |
static_cast<unsigned long>(bytes[1 ^ nBigEnd]);
if (ch >= 0xDC00 && ch < 0xE000)
{
if (ch >= 0xDC00 && ch < 0xE000) {
// Trailing (low) surrogate...ugh, wrong order
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
return;
}
else if (ch >= 0xD800 && ch < 0xDC00)
{
} else if (ch >= 0xD800 && ch < 0xDC00) {
// ch is a leading (high) surrogate
// Four byte UTF-8 code point
// Read the trailing (low) surrogate
for (;;)
{
for (;;) {
bytes[0] = GetNextByte();
bytes[1] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
return;
}
unsigned long chLow = (static_cast<unsigned long>(bytes[nBigEnd]) << 8) |
static_cast<unsigned long>(bytes[1 ^ nBigEnd]);
if (chLow < 0xDC00 || ch >= 0xE000)
{
// Trouble...not a low surrogate. Dump a REPLACEMENT CHARACTER into the stream.
if (chLow < 0xDC00 || ch >= 0xE000) {
// Trouble...not a low surrogate. Dump a REPLACEMENT CHARACTER into the
// stream.
QueueUnicodeCodepoint(m_readahead, CP_REPLACEMENT_CHARACTER);
// Deal with the next UTF-16 unit
if (chLow < 0xD800 || ch >= 0xE000)
{
if (chLow < 0xD800 || ch >= 0xE000) {
// Easiest case: queue the codepoint and return
QueueUnicodeCodepoint(m_readahead, ch);
return;
}
else
{
} else {
// Start the loop over with the new high surrogate
ch = chLow;
continue;
......@@ -388,40 +395,32 @@ namespace YAML
}
QueueUnicodeCodepoint(m_readahead, ch);
}
}
inline char* ReadBuffer(unsigned char* pBuffer)
{
inline char* ReadBuffer(unsigned char* pBuffer) {
return reinterpret_cast<char*>(pBuffer);
}
}
unsigned char Stream::GetNextByte() const
{
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable)
{
std::streambuf *pBuf = m_input.rdbuf();
m_nPrefetchedAvailable = static_cast<std::size_t>(pBuf->sgetn(ReadBuffer(m_pPrefetched), YAML_PREFETCH_SIZE));
unsigned char Stream::GetNextByte() const {
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable) {
std::streambuf* pBuf = m_input.rdbuf();
m_nPrefetchedAvailable = static_cast<std::size_t>(
pBuf->sgetn(ReadBuffer(m_pPrefetched), YAML_PREFETCH_SIZE));
m_nPrefetchedUsed = 0;
if (!m_nPrefetchedAvailable)
{
if (!m_nPrefetchedAvailable) {
m_input.setstate(std::ios_base::eofbit);
}
if (0 == m_nPrefetchedAvailable)
{
if (0 == m_nPrefetchedAvailable) {
return 0;
}
}
return m_pPrefetched[m_nPrefetchedUsed++];
}
}
void Stream::StreamInUtf32() const
{
static int indexes[2][4] = {
{3, 2, 1, 0},
{0, 1, 2, 3}
};
void Stream::StreamInUtf32() const {
static int indexes[2][4] = {{3, 2, 1, 0}, {0, 1, 2, 3}};
unsigned long ch = 0;
unsigned char bytes[4];
......@@ -431,17 +430,15 @@ namespace YAML
bytes[1] = GetNextByte();
bytes[2] = GetNextByte();
bytes[3] = GetNextByte();
if (!m_input.good())
{
if (!m_input.good()) {
return;
}
for (int i = 0; i < 4; ++i)
{
for (int i = 0; i < 4; ++i) {
ch <<= 8;
ch |= bytes[pIndexes[i]];
}
QueueUnicodeCodepoint(m_readahead, ch);
}
}
}
#ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/mark.h"
#include <cstddef>
......@@ -15,10 +16,8 @@
#include <set>
#include <string>
namespace YAML
{
class Stream: private noncopyable
{
namespace YAML {
class Stream : private noncopyable {
public:
friend class StreamCharSource;
......@@ -26,7 +25,7 @@ namespace YAML
~Stream();
operator bool() const;
bool operator !() const { return !static_cast <bool>(*this); }
bool operator!() const { return !static_cast<bool>(*this); }
char peek() const;
char get();
......@@ -42,7 +41,13 @@ namespace YAML
void ResetColumn() { m_mark.column = 0; }
private:
enum CharacterSet {utf8, utf16le, utf16be, utf32le, utf32be};
enum CharacterSet {
utf8,
utf16le,
utf16be,
utf32le,
utf32be
};
std::istream& m_input;
Mark m_mark;
......@@ -61,19 +66,17 @@ namespace YAML
void StreamInUtf16() const;
void StreamInUtf32() const;
unsigned char GetNextByte() const;
};
};
// CharAt
// . Unchecked access
inline char Stream::CharAt(size_t i) const {
return m_readahead[i];
}
// CharAt
// . Unchecked access
inline char Stream::CharAt(size_t i) const { return m_readahead[i]; }
inline bool Stream::ReadAheadTo(size_t i) const {
if(m_readahead.size() > i)
inline bool Stream::ReadAheadTo(size_t i) const {
if (m_readahead.size() > i)
return true;
return _ReadAheadTo(i);
}
}
}
#endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef>
namespace YAML
{
class StreamCharSource
{
namespace YAML {
class StreamCharSource {
public:
StreamCharSource(const Stream& stream): m_offset(0), m_stream(stream) {}
StreamCharSource(const StreamCharSource& source): m_offset(source.m_offset), m_stream(source.m_stream) {}
StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {}
StreamCharSource(const StreamCharSource& source)
: m_offset(source.m_offset), m_stream(source.m_stream) {}
~StreamCharSource() {}
operator bool() const;
char operator [] (std::size_t i) const { return m_stream.CharAt(m_offset + i); }
bool operator !() const { return !static_cast<bool>(*this); }
char operator[](std::size_t i) const { return m_stream.CharAt(m_offset + i); }
bool operator!() const { return !static_cast<bool>(*this); }
const StreamCharSource operator + (int i) const;
const StreamCharSource operator+(int i) const;
private:
std::size_t m_offset;
const Stream& m_stream;
StreamCharSource& operator = (const StreamCharSource&); // non-assignable
};
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
};
inline StreamCharSource::operator bool() const {
inline StreamCharSource::operator bool() const {
return m_stream.ReadAheadTo(m_offset);
}
}
inline const StreamCharSource StreamCharSource::operator + (int i) const {
inline const StreamCharSource StreamCharSource::operator+(int i) const {
StreamCharSource source(*this);
if(static_cast<int> (source.m_offset) + i >= 0)
if (static_cast<int>(source.m_offset) + i >= 0)
source.m_offset += i;
else
source.m_offset = 0;
return source;
}
}
}
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <cstddef>
namespace YAML
{
class StringCharSource
{
namespace YAML {
class StringCharSource {
public:
StringCharSource(const char *str, std::size_t size): m_str(str), m_size(size), m_offset(0) {}
StringCharSource(const char* str, std::size_t size)
: m_str(str), m_size(size), m_offset(0) {}
operator bool() const { return m_offset < m_size; }
char operator [] (std::size_t i) const { return m_str[m_offset + i]; }
bool operator !() const { return !static_cast<bool>(*this); }
char operator[](std::size_t i) const { return m_str[m_offset + i]; }
bool operator!() const { return !static_cast<bool>(*this); }
const StringCharSource operator + (int i) const {
const StringCharSource operator+(int i) const {
StringCharSource source(*this);
if(static_cast<int> (source.m_offset) + i >= 0)
if (static_cast<int>(source.m_offset) + i >= 0)
source.m_offset += i;
else
source.m_offset = 0;
return source;
}
StringCharSource& operator ++ () {
StringCharSource& operator++() {
++m_offset;
return *this;
}
StringCharSource& operator += (std::size_t offset) {
StringCharSource& operator+=(std::size_t offset) {
m_offset += offset;
return *this;
}
private:
const char *m_str;
const char* m_str;
std::size_t m_size;
std::size_t m_offset;
};
};
}
#endif // STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -4,11 +4,9 @@
#include <cassert>
#include <stdexcept>
namespace YAML
{
Tag::Tag(const Token& token): type(static_cast<TYPE>(token.data))
{
switch(type) {
namespace YAML {
Tag::Tag(const Token& token) : type(static_cast<TYPE>(token.data)) {
switch (type) {
case VERBATIM:
value = token.value;
break;
......@@ -27,11 +25,10 @@ namespace YAML
default:
assert(false);
}
}
}
const std::string Tag::Translate(const Directives& directives)
{
switch(type) {
const std::string Tag::Translate(const Directives& directives) {
switch (type) {
case VERBATIM:
return value;
case PRIMARY_HANDLE:
......@@ -47,6 +44,5 @@ namespace YAML
assert(false);
}
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
}
}
}
#ifndef TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace YAML
{
struct Token;
struct Directives;
namespace YAML {
struct Token;
struct Directives;
struct Tag {
struct Tag {
enum TYPE {
VERBATIM, PRIMARY_HANDLE, SECONDARY_HANDLE, NAMED_HANDLE, NON_SPECIFIC
VERBATIM,
PRIMARY_HANDLE,
SECONDARY_HANDLE,
NAMED_HANDLE,
NON_SPECIFIC
};
Tag(const Token& token);
......@@ -22,7 +27,7 @@ namespace YAML
TYPE type;
std::string handle, value;
};
};
}
#endif // TAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/mark.h"
#include <iostream>
#include <string>
#include <vector>
namespace YAML
{
const std::string TokenNames[] = {
"DIRECTIVE",
"DOC_START",
"DOC_END",
"BLOCK_SEQ_START",
"BLOCK_MAP_START",
"BLOCK_SEQ_END",
"BLOCK_MAP_END",
"BLOCK_ENTRY",
"FLOW_SEQ_START",
"FLOW_MAP_START",
"FLOW_SEQ_END",
"FLOW_MAP_END",
"FLOW_MAP_COMPACT",
"FLOW_ENTRY",
"KEY",
"VALUE",
"ANCHOR",
"ALIAS",
"TAG",
"SCALAR"
};
namespace YAML {
const std::string TokenNames[] = {
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
"BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
"FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
"FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
"ANCHOR", "ALIAS", "TAG", "SCALAR"};
struct Token {
struct Token {
// enums
enum STATUS { VALID, INVALID, UNVERIFIED };
enum STATUS {
VALID,
INVALID,
UNVERIFIED
};
enum TYPE {
DIRECTIVE,
DOC_START,
......@@ -64,11 +52,12 @@ namespace YAML
};
// data
Token(TYPE type_, const Mark& mark_): status(VALID), type(type_), mark(mark_), data(0) {}
Token(TYPE type_, const Mark& mark_)
: status(VALID), type(type_), mark(mark_), data(0) {}
friend std::ostream& operator << (std::ostream& out, const Token& token) {
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
out << TokenNames[token.type] << std::string(": ") << token.value;
for(std::size_t i=0;i<token.params.size();i++)
for (std::size_t i = 0; i < token.params.size(); i++)
out << std::string(" ") << token.params[i];
return out;
}
......@@ -77,9 +66,9 @@ namespace YAML
TYPE type;
Mark mark;
std::string value;
std::vector <std::string> params;
std::vector<std::string> params;
int data;
};
};
}
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
......@@ -3,22 +3,20 @@
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace Parser {
TEST NoEndOfMapFlow()
{
namespace Test {
namespace Parser {
TEST NoEndOfMapFlow() {
try {
HANDLE("---{header: {id: 1");
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::END_OF_MAP_FLOW));
return true;
}
return " no exception caught";
}
}
TEST PlainScalarStartingWithQuestionMark()
{
TEST PlainScalarStartingWithQuestionMark() {
HANDLE("foo: ?bar");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -27,10 +25,9 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
TEST NullStringScalar()
{
TEST NullStringScalar() {
HANDLE("foo: null");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -39,39 +36,41 @@ namespace Test
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
}
}
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed,
int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
}
catch (const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
if (!ret.ok) {
std::cout << "Parser test failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
if (ret.ok)
passed++;
total++;
}
}
}
}
bool RunParserTests()
{
bool RunParserTests() {
int passed = 0;
int total = 0;
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark,
"Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::NullStringScalar, "Null string scalar", passed, total);
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
}
......@@ -5,10 +5,9 @@
#include <cassert>
namespace Test {
namespace Spec {
// 2.1
TEST SeqScalars()
{
namespace Spec {
// 2.1
TEST SeqScalars() {
HANDLE(ex2_1);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -18,11 +17,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.2
TEST MappingScalarsToScalars()
{
// 2.2
TEST MappingScalarsToScalars() {
HANDLE(ex2_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -35,11 +33,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.3
TEST MappingScalarsToSequences()
{
// 2.3
TEST MappingScalarsToSequences() {
HANDLE(ex2_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -58,11 +55,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.4
TEST SequenceOfMappings()
{
// 2.4
TEST SequenceOfMappings() {
HANDLE(ex2_4);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -85,11 +81,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.5
TEST SequenceOfSequences()
{
// 2.5
TEST SequenceOfSequences() {
HANDLE(ex2_5);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -111,11 +106,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.6
TEST MappingOfMappings()
{
// 2.6
TEST MappingOfMappings() {
HANDLE(ex2_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -136,11 +130,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.7
TEST TwoDocumentsInAStream()
{
// 2.7
TEST TwoDocumentsInAStream() {
HANDLE(ex2_7);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -156,11 +149,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.8
TEST PlayByPlayFeed()
{
// 2.8
TEST PlayByPlayFeed() {
HANDLE(ex2_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -183,11 +175,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.9
TEST SingleDocumentWithTwoComments()
{
// 2.9
TEST SingleDocumentWithTwoComments() {
HANDLE(ex2_9);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -204,11 +195,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.10
TEST SimpleAnchor()
{
// 2.10
TEST SimpleAnchor() {
HANDLE(ex2_10);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -225,11 +215,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.11
TEST MappingBetweenSequences()
{
// 2.11
TEST MappingBetweenSequences() {
HANDLE(ex2_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -252,11 +241,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.12
TEST CompactNestedMapping()
{
// 2.12
TEST CompactNestedMapping() {
HANDLE(ex2_12);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -281,11 +269,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.13
TEST InLiteralsNewlinesArePreserved()
{
// 2.13
TEST InLiteralsNewlinesArePreserved() {
HANDLE(ex2_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -293,21 +280,19 @@ namespace Test {
"// || ||__");
EXPECT_DOC_END();
DONE();
}
}
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces()
{
// 2.14
TEST InFoldedScalarsNewlinesBecomeSpaces() {
HANDLE(ex2_14);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "Mark McGwire's year was crippled by a knee injury.");
EXPECT_DOC_END();
DONE();
}
}
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines()
{
// 2.15
TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() {
HANDLE(ex2_15);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -319,11 +304,10 @@ namespace Test {
"What a year!");
EXPECT_DOC_END();
DONE();
}
}
// 2.16
TEST IndentationDeterminesScope()
{
// 2.16
TEST IndentationDeterminesScope() {
HANDLE(ex2_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -338,11 +322,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.17
TEST QuotedScalars()
{
// 2.17
TEST QuotedScalars() {
HANDLE(ex2_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -361,11 +344,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.18
TEST MultiLineFlowScalars()
{
// 2.18
TEST MultiLineFlowScalars() {
HANDLE(ex2_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -376,13 +358,12 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 2.19 - 2.22 schema tags
// TODO: 2.19 - 2.22 schema tags
// 2.23
TEST VariousExplicitTags()
{
// 2.23
TEST VariousExplicitTags() {
HANDLE(ex2_23);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -402,11 +383,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.24
TEST GlobalTags()
{
// 2.24
TEST GlobalTags() {
HANDLE(ex2_24);
EXPECT_DOC_START();
EXPECT_SEQ_START("tag:clarkevans.com,2002:shape", 0);
......@@ -443,11 +423,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.25
TEST UnorderedSets()
{
// 2.25
TEST UnorderedSets() {
HANDLE(ex2_25);
EXPECT_DOC_START();
EXPECT_MAP_START("tag:yaml.org,2002:set", 0);
......@@ -460,11 +439,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.26
TEST OrderedMappings()
{
// 2.26
TEST OrderedMappings() {
HANDLE(ex2_26);
EXPECT_DOC_START();
EXPECT_SEQ_START("tag:yaml.org,2002:omap", 0);
......@@ -483,11 +461,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.27
TEST Invoice()
{
// 2.27
TEST Invoice() {
HANDLE(ex2_27);
EXPECT_DOC_START();
EXPECT_MAP_START("tag:clarkevans.com,2002:invoice", 0);
......@@ -545,15 +522,16 @@ namespace Test {
EXPECT_SCALAR("?", 0, "total");
EXPECT_SCALAR("?", 0, "4443.52");
EXPECT_SCALAR("?", 0, "comments");
EXPECT_SCALAR("?", 0, "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
EXPECT_SCALAR(
"?", 0,
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 2.28
TEST LogFile()
{
// 2.28
TEST LogFile() {
HANDLE(ex2_28);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -605,13 +583,12 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 5.1 - 5.2 BOM
// TODO: 5.1 - 5.2 BOM
// 5.3
TEST BlockStructureIndicators()
{
// 5.3
TEST BlockStructureIndicators() {
HANDLE(ex5_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -630,11 +607,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.4
TEST FlowStructureIndicators()
{
// 5.4
TEST FlowStructureIndicators() {
HANDLE(ex5_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -653,18 +629,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.5
TEST CommentIndicator()
{
// 5.5
TEST CommentIndicator() {
HANDLE(ex5_5);
DONE();
}
}
// 5.6
TEST NodePropertyIndicators()
{
// 5.6
TEST NodePropertyIndicators() {
HANDLE(ex5_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -675,11 +649,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.7
TEST BlockScalarIndicators()
{
// 5.7
TEST BlockScalarIndicators() {
HANDLE(ex5_7);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -690,11 +663,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.8
TEST QuotedScalarIndicators()
{
// 5.8
TEST QuotedScalarIndicators() {
HANDLE(ex5_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -705,14 +677,13 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// TODO: 5.9 directive
// TODO: 5.10 reserved indicator
// 5.11
TEST LineBreakCharacters()
{
// 5.11
TEST LineBreakCharacters() {
HANDLE(ex5_11);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0,
......@@ -720,11 +691,10 @@ namespace Test {
"Line break (glyphed)\n");
EXPECT_DOC_END();
DONE();
}
}
// 5.12
TEST TabsAndSpaces()
{
// 5.12
TEST TabsAndSpaces() {
HANDLE(ex5_12);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -738,33 +708,34 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 5.13
TEST EscapedCharacters()
{
// 5.13
TEST EscapedCharacters() {
HANDLE(ex5_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
EXPECT_SCALAR("!", 0,
"Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " +
std::string("\x00", 1) +
" \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
EXPECT_DOC_END();
DONE();
}
}
// 5.14
TEST InvalidEscapedCharacters()
{
// 5.14
TEST InvalidEscapedCharacters() {
try {
HANDLE(ex5_14);
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
return true;
}
return " no exception caught";
}
}
// 6.1
TEST IndentationSpaces()
{
// 6.1
TEST IndentationSpaces() {
HANDLE(ex6_1);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -782,11 +753,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.2
TEST IndentationIndicators()
{
// 6.2
TEST IndentationIndicators() {
HANDLE(ex6_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -801,11 +771,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.3
TEST SeparationSpaces()
{
// 6.3
TEST SeparationSpaces() {
HANDLE(ex6_3);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -820,11 +789,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.4
TEST LinePrefixes()
{
// 6.4
TEST LinePrefixes() {
HANDLE(ex6_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -837,11 +805,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.5
TEST EmptyLines()
{
// 6.5
TEST EmptyLines() {
HANDLE(ex6_5);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -852,41 +819,37 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.6
TEST LineFolding()
{
// 6.6
TEST LineFolding() {
HANDLE(ex6_6);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "trimmed\n\n\nas space");
EXPECT_DOC_END();
DONE();
}
}
// 6.7
TEST BlockFolding()
{
// 6.7
TEST BlockFolding() {
HANDLE(ex6_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo \n\n\t bar\n\nbaz\n");
EXPECT_DOC_END();
DONE();
}
}
// 6.8
TEST FlowFolding()
{
// 6.8
TEST FlowFolding() {
HANDLE(ex6_8);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " foo\nbar\nbaz ");
EXPECT_DOC_END();
DONE();
}
}
// 6.9
TEST SeparatedComment()
{
// 6.9
TEST SeparatedComment() {
HANDLE(ex6_9);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -895,18 +858,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.10
TEST CommentLines()
{
// 6.10
TEST CommentLines() {
HANDLE(ex6_10);
DONE();
}
}
// 6.11
TEST MultiLineComments()
{
// 6.11
TEST MultiLineComments() {
HANDLE(ex6_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -915,11 +876,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.12
TEST SeparationSpacesII()
{
// 6.12
TEST SeparationSpacesII() {
HANDLE(ex6_12);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -938,71 +898,67 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.13
TEST ReservedDirectives()
{
// 6.13
TEST ReservedDirectives() {
HANDLE(ex6_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.14
TEST YAMLDirective()
{
// 6.14
TEST YAMLDirective() {
HANDLE(ex6_14);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.15
TEST InvalidRepeatedYAMLDirective()
{
// 6.15
TEST InvalidRepeatedYAMLDirective() {
try {
HANDLE(ex6_15);
} catch(const YAML::ParserException& e) {
if(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE)
}
catch (const YAML::ParserException& e) {
if (e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE)
return true;
throw;
}
return " No exception was thrown";
}
}
// 6.16
TEST TagDirective()
{
// 6.16
TEST TagDirective() {
HANDLE(ex6_16);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:yaml.org,2002:str", 0, "foo");
EXPECT_DOC_END();
DONE();
}
}
// 6.17
TEST InvalidRepeatedTagDirective()
{
// 6.17
TEST InvalidRepeatedTagDirective() {
try {
HANDLE(ex6_17);
} catch(const YAML::ParserException& e) {
if(e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
}
catch (const YAML::ParserException& e) {
if (e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
return true;
throw;
}
return " No exception was thrown";
}
}
// 6.18
TEST PrimaryTagHandle()
{
// 6.18
TEST PrimaryTagHandle() {
HANDLE(ex6_18);
EXPECT_DOC_START();
EXPECT_SCALAR("!foo", 0, "bar");
......@@ -1011,31 +967,28 @@ namespace Test {
EXPECT_SCALAR("tag:example.com,2000:app/foo", 0, "bar");
EXPECT_DOC_END();
DONE();
}
}
// 6.19
TEST SecondaryTagHandle()
{
// 6.19
TEST SecondaryTagHandle() {
HANDLE(ex6_19);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:example.com,2000:app/int", 0, "1 - 3");
EXPECT_DOC_END();
DONE();
}
}
// 6.20
TEST TagHandles()
{
// 6.20
TEST TagHandles() {
HANDLE(ex6_20);
EXPECT_DOC_START();
EXPECT_SCALAR("tag:example.com,2000:app/foo", 0, "bar");
EXPECT_DOC_END();
DONE();
}
}
// 6.21
TEST LocalTagPrefix()
{
// 6.21
TEST LocalTagPrefix() {
HANDLE(ex6_21);
EXPECT_DOC_START();
EXPECT_SCALAR("!my-light", 0, "fluorescent");
......@@ -1044,11 +997,10 @@ namespace Test {
EXPECT_SCALAR("!my-light", 0, "green");
EXPECT_DOC_END();
DONE();
}
}
// 6.22
TEST GlobalTagPrefix()
{
// 6.22
TEST GlobalTagPrefix() {
HANDLE(ex6_22);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1056,11 +1008,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.23
TEST NodeProperties()
{
// 6.23
TEST NodeProperties() {
HANDLE(ex6_23);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1071,11 +1022,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.24
TEST VerbatimTags()
{
// 6.24
TEST VerbatimTags() {
HANDLE(ex6_24);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1084,18 +1034,16 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.25
TEST InvalidVerbatimTags()
{
// 6.25
TEST InvalidVerbatimTags() {
HANDLE(ex6_25);
return " not implemented yet";
}
}
// 6.26
TEST TagShorthands()
{
// 6.26
TEST TagShorthands() {
HANDLE(ex6_26);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1105,30 +1053,30 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.27
TEST InvalidTagShorthands()
{
// 6.27
TEST InvalidTagShorthands() {
bool threw = false;
try {
HANDLE(ex6_27a);
} catch(const YAML::ParserException& e) {
}
catch (const YAML::ParserException& e) {
threw = true;
if(e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
if (e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
throw;
}
if(!threw)
if (!threw)
return " No exception was thrown for a tag with no suffix";
HANDLE(ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
HANDLE(
ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
return " not implemented yet";
}
}
// 6.28
TEST NonSpecificTags()
{
// 6.28
TEST NonSpecificTags() {
HANDLE(ex6_28);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1138,11 +1086,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 6.29
TEST NodeAnchors()
{
// 6.29
TEST NodeAnchors() {
HANDLE(ex6_29);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1153,11 +1100,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.1
TEST AliasNodes()
{
// 7.1
TEST AliasNodes() {
HANDLE(ex7_1);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1172,11 +1118,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.2
TEST EmptyNodes()
{
// 7.2
TEST EmptyNodes() {
HANDLE(ex7_2);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1187,11 +1132,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.3
TEST CompletelyEmptyNodes()
{
// 7.3
TEST CompletelyEmptyNodes() {
HANDLE(ex7_3);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1202,11 +1146,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.4
TEST DoubleQuotedImplicitKeys()
{
// 7.4
TEST DoubleQuotedImplicitKeys() {
HANDLE(ex7_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1220,41 +1163,38 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.5
TEST DoubleQuotedLineBreaks()
{
// 7.5
TEST DoubleQuotedLineBreaks() {
HANDLE(ex7_5);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "folded to a space,\nto a line feed, or \t \tnon-content");
EXPECT_SCALAR("!", 0,
"folded to a space,\nto a line feed, or \t \tnon-content");
EXPECT_DOC_END();
DONE();
}
}
// 7.6
TEST DoubleQuotedLines()
{
// 7.6
TEST DoubleQuotedLines() {
HANDLE(ex7_6);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty ");
EXPECT_DOC_END();
DONE();
}
}
// 7.7
TEST SingleQuotedCharacters()
{
// 7.7
TEST SingleQuotedCharacters() {
HANDLE(ex7_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "here's to \"quotes\"");
EXPECT_DOC_END();
DONE();
}
}
// 7.8
TEST SingleQuotedImplicitKeys()
{
// 7.8
TEST SingleQuotedImplicitKeys() {
HANDLE(ex7_8);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1268,21 +1208,19 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.9
TEST SingleQuotedLines()
{
// 7.9
TEST SingleQuotedLines() {
HANDLE(ex7_9);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty ");
EXPECT_DOC_END();
DONE();
}
}
// 7.10
TEST PlainCharacters()
{
// 7.10
TEST PlainCharacters() {
HANDLE(ex7_10);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1301,11 +1239,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.11
TEST PlainImplicitKeys()
{
// 7.11
TEST PlainImplicitKeys() {
HANDLE(ex7_11);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1319,21 +1256,19 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.12
TEST PlainLines()
{
// 7.12
TEST PlainLines() {
HANDLE(ex7_12);
EXPECT_DOC_START();
EXPECT_SCALAR("?", 0, "1st non-empty\n2nd non-empty 3rd non-empty");
EXPECT_DOC_END();
DONE();
}
}
// 7.13
TEST FlowSequence()
{
// 7.13
TEST FlowSequence() {
HANDLE(ex7_13);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1348,11 +1283,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.14
TEST FlowSequenceEntries()
{
// 7.14
TEST FlowSequenceEntries() {
HANDLE(ex7_14);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1369,11 +1303,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.15
TEST FlowMappings()
{
// 7.15
TEST FlowMappings() {
HANDLE(ex7_15);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1392,11 +1325,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.16
TEST FlowMappingEntries()
{
// 7.16
TEST FlowMappingEntries() {
HANDLE(ex7_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1409,11 +1341,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.17
TEST FlowMappingSeparateValues()
{
// 7.17
TEST FlowMappingSeparateValues() {
HANDLE(ex7_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1428,11 +1359,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.18
TEST FlowMappingAdjacentValues()
{
// 7.18
TEST FlowMappingAdjacentValues() {
HANDLE(ex7_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1445,11 +1375,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.19
TEST SinglePairFlowMappings()
{
// 7.19
TEST SinglePairFlowMappings() {
HANDLE(ex7_19);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1460,11 +1389,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.20
TEST SinglePairExplicitEntry()
{
// 7.20
TEST SinglePairExplicitEntry() {
HANDLE(ex7_20);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1475,11 +1403,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.21
TEST SinglePairImplicitEntries()
{
// 7.21
TEST SinglePairImplicitEntries() {
HANDLE(ex7_21);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1507,25 +1434,24 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.22
TEST InvalidImplicitKeys()
{
// 7.22
TEST InvalidImplicitKeys() {
try {
HANDLE(ex7_22);
} catch(const YAML::Exception& e) {
if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
}
catch (const YAML::Exception& e) {
if (e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
return true;
throw;
}
return " no exception thrown";
}
}
// 7.23
TEST FlowContent()
{
// 7.23
TEST FlowContent() {
HANDLE(ex7_23);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1543,11 +1469,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 7.24
TEST FlowNodes()
{
// 7.24
TEST FlowNodes() {
HANDLE(ex7_24);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1559,11 +1484,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.1
TEST BlockScalarHeader()
{
// 8.1
TEST BlockScalarHeader() {
HANDLE(ex8_1);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1574,11 +1498,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.2
TEST BlockIndentationHeader()
{
// 8.2
TEST BlockIndentationHeader() {
HANDLE(ex8_2);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1589,62 +1512,66 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.3
TEST InvalidBlockScalarIndentationIndicators()
{
// 8.3
TEST InvalidBlockScalarIndentationIndicators() {
{
bool threw = false;
try {
HANDLE(ex8_3a);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented auto-detecting indentation for a literal block scalar";
if (!threw)
return " no exception thrown for less indented auto-detecting "
"indentation for a literal block scalar";
}
{
bool threw = false;
try {
HANDLE(ex8_3b);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented auto-detecting indentation for a folded block scalar";
if (!threw)
return " no exception thrown for less indented auto-detecting "
"indentation for a folded block scalar";
}
{
bool threw = false;
try {
HANDLE(ex8_3c);
} catch(const YAML::Exception& e) {
if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
}
catch (const YAML::Exception& e) {
if (e.msg != YAML::ErrorMsg::END_OF_SEQ)
throw;
threw = true;
}
if(!threw)
return " no exception thrown for less indented explicit indentation for a literal block scalar";
if (!threw)
return " no exception thrown for less indented explicit indentation for "
"a literal block scalar";
}
return true;
}
}
// 8.4
TEST ChompingFinalLineBreak()
{
// 8.4
TEST ChompingFinalLineBreak() {
HANDLE(ex8_4);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1657,11 +1584,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.5
TEST ChompingTrailingLines()
{
// 8.5
TEST ChompingTrailingLines() {
HANDLE(ex8_5);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1670,15 +1596,15 @@ namespace Test {
EXPECT_SCALAR("?", 0, "clip");
EXPECT_SCALAR("!", 0, "# text\n");
EXPECT_SCALAR("?", 0, "keep");
EXPECT_SCALAR("!", 0, "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
EXPECT_SCALAR("!", 0, "# text\n"); // Note: I believe this is a bug in the
// YAML spec - it should be "# text\n\n"
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.6
TEST EmptyScalarChomping()
{
// 8.6
TEST EmptyScalarChomping() {
HANDLE(ex8_6);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1691,81 +1617,81 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.7
TEST LiteralScalar()
{
// 8.7
TEST LiteralScalar() {
HANDLE(ex8_7);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "literal\n\ttext\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.8
TEST LiteralContent()
{
// 8.8
TEST LiteralContent() {
HANDLE(ex8_8);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\n\nliteral\n \n\ntext\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.9
TEST FoldedScalar()
{
// 8.9
TEST FoldedScalar() {
HANDLE(ex8_9);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "folded text\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.10
TEST FoldedLines()
{
// 8.10
TEST FoldedLines() {
HANDLE(ex8_10);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.11
TEST MoreIndentedLines()
{
// 8.11
TEST MoreIndentedLines() {
HANDLE(ex8_11);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.12
TEST EmptySeparationLines()
{
// 8.12
TEST EmptySeparationLines() {
HANDLE(ex8_12);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.13
TEST FinalEmptyLines()
{
// 8.13
TEST FinalEmptyLines() {
HANDLE(ex8_13);
EXPECT_DOC_START();
EXPECT_SCALAR("!", 0, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n");
EXPECT_SCALAR("!", 0,
"\nfolded line\nnext line\n * bullet\n\n * list\n * "
"lines\n\nlast line\n");
EXPECT_DOC_END();
DONE();
}
}
// 8.14
TEST BlockSequence()
{
// 8.14
TEST BlockSequence() {
HANDLE(ex8_14);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1780,11 +1706,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.15
TEST BlockSequenceEntryTypes()
{
// 8.15
TEST BlockSequenceEntryTypes() {
HANDLE(ex8_15);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1801,11 +1726,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.16
TEST BlockMappings()
{
// 8.16
TEST BlockMappings() {
HANDLE(ex8_16);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1817,11 +1741,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.17
TEST ExplicitBlockMappingEntries()
{
// 8.17
TEST ExplicitBlockMappingEntries() {
HANDLE(ex8_17);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1835,11 +1758,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.18
TEST ImplicitBlockMappingEntries()
{
// 8.18
TEST ImplicitBlockMappingEntries() {
HANDLE(ex8_18);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1854,11 +1776,10 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.19
TEST CompactBlockMappings()
{
// 8.19
TEST CompactBlockMappings() {
HANDLE(ex8_19);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1879,11 +1800,10 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.20
TEST BlockNodeTypes()
{
// 8.20
TEST BlockNodeTypes() {
HANDLE(ex8_20);
EXPECT_DOC_START();
EXPECT_SEQ_START("?", 0);
......@@ -1896,26 +1816,25 @@ namespace Test {
EXPECT_SEQ_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.21
TEST BlockScalarNodes()
{
// 8.21
TEST BlockScalarNodes() {
HANDLE(ex8_21);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
EXPECT_SCALAR("?", 0, "literal");
EXPECT_SCALAR("!", 0, "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n"
EXPECT_SCALAR("!", 0, "value"); // Note: I believe this is a bug in the YAML
// spec - it should be "value\n"
EXPECT_SCALAR("?", 0, "folded");
EXPECT_SCALAR("!foo", 0, "value");
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
// 8.22
TEST BlockCollectionNodes()
{
// 8.22
TEST BlockCollectionNodes() {
HANDLE(ex8_22);
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
......@@ -1934,6 +1853,6 @@ namespace Test {
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
}
}
}
#ifndef EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace Test {
bool RunEmitterTests();
bool RunEmitterTests();
}
#endif // EMITTERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
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