Commit a3961d04 by Jesse Beder

Continued working on scanner.

We're now using exceptions for errors, and scanning/pushing tokens is exception-safe (using a set of "limbo tokens").
parent 8ae7b481
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "node.h" #include "node.h"
#include "parser.h" #include "parser.h"
#include "scanner.h" #include "scanner.h"
#include "exceptions.h"
#include <fstream> #include <fstream>
namespace YAML namespace YAML
...@@ -32,7 +33,11 @@ namespace YAML ...@@ -32,7 +33,11 @@ namespace YAML
std::ifstream fin(fileName.c_str()); std::ifstream fin(fileName.c_str());
Scanner scanner(fin); Scanner scanner(fin);
try {
scanner.Scan(); scanner.Scan();
} catch(const UnknownToken& e) {
}
// if(!scanner) // if(!scanner)
// return; // return;
......
#pragma once
#include <exception>
namespace YAML
{
class Exception: public std::exception {};
class UnknownToken: public Exception {};
class IllegalBlockEntry: public Exception {};
class IllegalMapKey: public Exception {};
class IllegalMapValue: public Exception {};
class IllegalScalar: public Exception {};
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <string> #include <string>
#include <queue> #include <queue>
#include <stack> #include <stack>
#include <set>
namespace YAML namespace YAML
{ {
...@@ -12,6 +13,19 @@ namespace YAML ...@@ -12,6 +13,19 @@ namespace YAML
namespace Keys namespace Keys
{ {
const char Comment = '#'; const char Comment = '#';
const char FlowSeqStart = '[';
const char FlowSeqEnd = ']';
const char FlowMapStart = '{';
const char FlowMapEnd = '}';
const char FlowEntry = ',';
const char BlockEntry = '-';
const char Key = '?';
const char Value = ':';
const char Alias = '*';
const char Anchor = '&';
const char Tag = '!';
const char LiteralScalar = '|';
const char FoldedScalar = '>';
} }
class Scanner class Scanner
...@@ -20,8 +34,10 @@ namespace YAML ...@@ -20,8 +34,10 @@ namespace YAML
Scanner(std::istream& in); Scanner(std::istream& in);
~Scanner(); ~Scanner();
Token *ScanNextToken(); void ScanNextToken();
void ScanToNextToken(); void ScanToNextToken();
void PushIndentTo(int column, bool sequence);
void PopIndentTo(int column);
void Scan(); void Scan();
...@@ -36,6 +52,12 @@ namespace YAML ...@@ -36,6 +52,12 @@ namespace YAML
bool IsBlank(); bool IsBlank();
bool IsDocumentStart(); bool IsDocumentStart();
bool IsDocumentEnd(); bool IsDocumentEnd();
bool IsBlockEntry();
bool IsKey();
bool IsValue();
bool IsPlainScalar();
template <typename T> void ScanAndEnqueue(T *pToken);
template <typename T> T *ScanToken(T *pToken); template <typename T> T *ScanToken(T *pToken);
private: private:
...@@ -45,6 +67,7 @@ namespace YAML ...@@ -45,6 +67,7 @@ namespace YAML
// the output (tokens) // the output (tokens)
std::queue <Token *> m_tokens; std::queue <Token *> m_tokens;
std::set <Token *> m_limboTokens;
// state info // state info
bool m_startedStream; bool m_startedStream;
......
...@@ -3,8 +3,25 @@ ...@@ -3,8 +3,25 @@
namespace YAML namespace YAML
{ {
class Token {}; class Token {};
class StreamStartToken: public Token {}; class StreamStartToken: public Token {};
class StreamEndToken: public Token {}; class StreamEndToken: public Token {};
class DocumentStartToken: public Token {}; class DocumentStartToken: public Token {};
class DocumentEndToken: public Token {}; class DocumentEndToken: public Token {};
class BlockSeqStartToken: public Token {};
class BlockMapStartToken: public Token {};
class BlockEndToken: public Token {};
class BlockEntryToken: public Token {};
class FlowSeqStartToken: public Token {};
class FlowMapStartToken: public Token {};
class FlowSeqEndToken: public Token {};
class FlowMapEndToken: public Token {};
class FlowEntryToken: public Token {};
class KeyToken: public Token {};
class ValueToken: public Token {};
class PlainScalarToken: public Token {};
} }
...@@ -212,6 +212,10 @@ ...@@ -212,6 +212,10 @@
> >
</File> </File>
<File <File
RelativePath=".\exceptions.h"
>
</File>
<File
RelativePath=".\map.h" RelativePath=".\map.h"
> >
</File> </File>
......
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