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 IllegalScalar: public Exception {};
class IllegalTabInScalar: public Exception {};
class IllegalFlowEnd: public Exception {};
class DocIndicatorInQuote: public Exception {};
class EOFInQuote: 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
// . Returns the next token on the queue, and scans if only we need to.
Token *Scanner::GetNextToken()

View file

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

View file

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