yaml-cpp/scanner.h

75 lines
1.5 KiB
C
Raw Normal View History

2008-06-26 13:05:28 +04:00
#pragma once
#include <ios>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include "regex.h"
#include "stream.h"
2008-06-26 13:05:28 +04:00
namespace YAML
{
2008-06-28 00:54:43 +04:00
struct Token;
2008-06-26 13:05:28 +04:00
class Scanner
{
public:
Scanner(std::istream& in);
~Scanner();
Token *GetNextToken();
void Scan();
private:
// scanning
void ScanNextToken();
2008-06-26 13:05:28 +04:00
void ScanToNextToken();
Token *PushIndentTo(int column, bool sequence);
void PopIndentTo(int column);
2008-06-26 13:05:28 +04:00
// checking input
void InsertSimpleKey();
bool VerifySimpleKey();
void VerifyAllSimpleKeys();
2008-06-27 02:00:39 +04:00
bool IsWhitespaceToBeEaten(char ch);
2008-06-26 13:05:28 +04:00
bool IsDocumentStart();
bool IsDocumentEnd();
bool IsBlockEntry();
bool IsKey();
bool IsValue();
bool IsPlainScalar();
struct SimpleKey {
SimpleKey(int pos_, int line_, int column_, int flowLevel_);
void Validate();
void Invalidate();
int pos, line, column, flowLevel;
bool required;
Token *pMapStart, *pKey;
};
template <typename T> void ScanAndEnqueue(T *pToken);
2008-06-26 13:05:28 +04:00
template <typename T> T *ScanToken(T *pToken);
private:
// the stream
Stream INPUT;
2008-06-26 13:05:28 +04:00
// the output (tokens)
std::queue <Token *> m_tokens;
std::set <Token *> m_limboTokens;
2008-06-26 13:05:28 +04:00
// state info
bool m_startedStream, m_endedStream;
2008-06-26 13:05:28 +04:00
bool m_simpleKeyAllowed;
int m_flowLevel; // number of unclosed '[' and '{' indicators
bool m_isLastKeyValid;
std::stack <SimpleKey> m_simpleKeys;
2008-06-26 13:05:28 +04:00
std::stack <int> m_indents;
};
}