Small refactoring.

This commit is contained in:
Jesse Beder 2008-06-28 22:05:51 +00:00
parent 72b443375c
commit 2e27c5d9c3
4 changed files with 20 additions and 42 deletions

View file

@ -12,6 +12,7 @@ namespace YAML
class IllegalMapValue: public Exception {}; class IllegalMapValue: public Exception {};
class IllegalScalar: public Exception {}; class IllegalScalar: public Exception {};
class IllegalTabInScalar: public Exception {}; class IllegalTabInScalar: public Exception {};
class IllegalFlowEnd: public Exception {};
class DocIndicatorInQuote: public Exception {}; class DocIndicatorInQuote: public Exception {};
class EOFInQuote: public Exception {}; class EOFInQuote: public Exception {};
class RequiredSimpleKeyNotFound: public Exception {}; class RequiredSimpleKeyNotFound: public Exception {};

View file

@ -288,22 +288,6 @@ namespace YAML
} }
} }
// IncreaseFlowLevel
void Scanner::IncreaseFlowLevel()
{
// TODO: Push simple key
m_flowLevel++;
}
// DecreaseFlowLevel
void Scanner::DecreaseFlowLevel()
{
if(m_flowLevel > 0) {
m_flowLevel--;
// TODO: Pop simple key
}
}
// GetNextToken // GetNextToken
// . Returns the next token on the queue, and scans if only we need to. // . Returns the next token on the queue, and scans if only we need to.
Token *Scanner::GetNextToken() Token *Scanner::GetNextToken()

View file

@ -22,8 +22,6 @@ namespace YAML
void ScanToNextToken(); void ScanToNextToken();
Token *PushIndentTo(int column, bool sequence); Token *PushIndentTo(int column, bool sequence);
void PopIndentTo(int column); void PopIndentTo(int column);
void IncreaseFlowLevel();
void DecreaseFlowLevel();
void InsertSimpleKey(); void InsertSimpleKey();
bool ValidateSimpleKey(); bool ValidateSimpleKey();

View file

@ -63,7 +63,7 @@ namespace YAML
{ {
// flow sequences can be simple keys // flow sequences can be simple keys
InsertSimpleKey(); InsertSimpleKey();
IncreaseFlowLevel(); m_flowLevel++;
m_simpleKeyAllowed = true; m_simpleKeyAllowed = true;
// eat // eat
@ -76,7 +76,7 @@ namespace YAML
{ {
// flow maps can be simple keys // flow maps can be simple keys
InsertSimpleKey(); InsertSimpleKey();
IncreaseFlowLevel(); m_flowLevel++;
m_simpleKeyAllowed = true; m_simpleKeyAllowed = true;
// eat // eat
@ -87,8 +87,10 @@ namespace YAML
// FlowSeqEndToken // FlowSeqEndToken
template <> FlowSeqEndToken *Scanner::ScanToken(FlowSeqEndToken *pToken) template <> FlowSeqEndToken *Scanner::ScanToken(FlowSeqEndToken *pToken)
{ {
// ValidateSimpleKey(); if(m_flowLevel == 0)
DecreaseFlowLevel(); throw IllegalFlowEnd();
m_flowLevel--;
m_simpleKeyAllowed = false; m_simpleKeyAllowed = false;
// eat // eat
@ -99,8 +101,10 @@ namespace YAML
// FlowMapEndToken // FlowMapEndToken
template <> FlowMapEndToken *Scanner::ScanToken(FlowMapEndToken *pToken) template <> FlowMapEndToken *Scanner::ScanToken(FlowMapEndToken *pToken)
{ {
//ValidateSimpleKey(); if(m_flowLevel == 0)
DecreaseFlowLevel(); throw IllegalFlowEnd();
m_flowLevel--;
m_simpleKeyAllowed = false; m_simpleKeyAllowed = false;
// eat // eat
@ -111,7 +115,6 @@ namespace YAML
// FlowEntryToken // FlowEntryToken
template <> FlowEntryToken *Scanner::ScanToken(FlowEntryToken *pToken) template <> FlowEntryToken *Scanner::ScanToken(FlowEntryToken *pToken)
{ {
//ValidateSimpleKey();
m_simpleKeyAllowed = true; m_simpleKeyAllowed = true;
// eat // eat
@ -122,19 +125,15 @@ namespace YAML
// BlockEntryToken // BlockEntryToken
template <> BlockEntryToken *Scanner::ScanToken(BlockEntryToken *pToken) template <> BlockEntryToken *Scanner::ScanToken(BlockEntryToken *pToken)
{ {
//ValidateSimpleKey();
// we better be in the block context! // we better be in the block context!
if(m_flowLevel == 0) { if(m_flowLevel > 0)
throw IllegalBlockEntry();
// can we put it here? // can we put it here?
if(!m_simpleKeyAllowed) if(!m_simpleKeyAllowed)
throw IllegalBlockEntry(); throw IllegalBlockEntry();
PushIndentTo(m_column, true); // , -1 PushIndentTo(m_column, true);
} else {
// TODO: throw?
}
m_simpleKeyAllowed = true; m_simpleKeyAllowed = true;
// eat // eat
@ -145,7 +144,7 @@ namespace YAML
// KeyToken // KeyToken
template <> KeyToken *Scanner::ScanToken(KeyToken *pToken) template <> KeyToken *Scanner::ScanToken(KeyToken *pToken)
{ {
// are we in block context? // handle keys diffently in the block context (and manage indents)
if(m_flowLevel == 0) { if(m_flowLevel == 0) {
if(!m_simpleKeyAllowed) if(!m_simpleKeyAllowed)
throw IllegalMapKey(); throw IllegalMapKey();
@ -153,8 +152,6 @@ namespace YAML
PushIndentTo(m_column, false); PushIndentTo(m_column, false);
} }
// TODO: "remove simple key"
// can only put a simple key here if we're in block context // can only put a simple key here if we're in block context
if(m_flowLevel == 0) if(m_flowLevel == 0)
m_simpleKeyAllowed = true; m_simpleKeyAllowed = true;
@ -170,13 +167,11 @@ namespace YAML
template <> ValueToken *Scanner::ScanToken(ValueToken *pToken) template <> ValueToken *Scanner::ScanToken(ValueToken *pToken)
{ {
// does this follow a simple key? // does this follow a simple key?
// bool isValidKey = ValidateSimpleKey();
if(m_isLastKeyValid) { if(m_isLastKeyValid) {
// can't follow a simple key with another simple key (dunno why, though - it seems fine) // can't follow a simple key with another simple key (dunno why, though - it seems fine)
m_simpleKeyAllowed = false; m_simpleKeyAllowed = false;
} else { } else {
// are we in block context? // handle values diffently in the block context (and manage indents)
if(m_flowLevel == 0) { if(m_flowLevel == 0) {
if(!m_simpleKeyAllowed) if(!m_simpleKeyAllowed)
throw IllegalMapValue(); throw IllegalMapValue();