diff --git a/exceptions.h b/exceptions.h index 1e0867b8b1..3540519d8b 100644 --- a/exceptions.h +++ b/exceptions.h @@ -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 {}; diff --git a/scanner.cpp b/scanner.cpp index 1237a60133..7c77b52291 100644 --- a/scanner.cpp +++ b/scanner.cpp @@ -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() diff --git a/scanner.h b/scanner.h index b83b8a2bc5..037b4b8072 100644 --- a/scanner.h +++ b/scanner.h @@ -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(); diff --git a/scantoken.cpp b/scantoken.cpp index 6cd08d2789..3b8d7efb85 100644 --- a/scantoken.cpp +++ b/scantoken.cpp @@ -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