diff --git a/src/scanner.h b/src/scanner.h index 8764719..e4590ef 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -33,7 +33,7 @@ namespace YAML // checking input void InsertSimpleKey(); - bool VerifySimpleKey(); + bool VerifySimpleKey(bool force = false); void VerifyAllSimpleKeys(); bool IsWhitespaceToBeEaten(char ch); diff --git a/src/simplekey.cpp b/src/simplekey.cpp index 32a1761..f971c54 100644 --- a/src/simplekey.cpp +++ b/src/simplekey.cpp @@ -50,7 +50,8 @@ namespace YAML // VerifySimpleKey // . Determines whether the latest simple key to be added is valid, // and if so, makes it valid. - bool Scanner::VerifySimpleKey() + // . If 'force' is true, then we'll pop no matter what (whether we can verify it or not). + bool Scanner::VerifySimpleKey(bool force) { m_isLastKeyValid = false; if(m_simpleKeys.empty()) @@ -60,8 +61,11 @@ namespace YAML SimpleKey key = m_simpleKeys.top(); // only validate if we're in the correct flow level - if(key.flowLevel != m_flowLevel) + if(key.flowLevel != m_flowLevel) { + if(force) + m_simpleKeys.pop(); return false; + } m_simpleKeys.pop(); @@ -94,9 +98,11 @@ namespace YAML return isValid; } + // VerifyAllSimplyKeys + // . Pops all simple keys (with checking, but if we can't verify one, then pop it anyways). void Scanner::VerifyAllSimpleKeys() { while(!m_simpleKeys.empty()) - VerifySimpleKey(); + VerifySimpleKey(true); } } diff --git a/yaml-reader/tests/test.yaml b/yaml-reader/tests/test.yaml index 662ec0c..6938c5c 100644 --- a/yaml-reader/tests/test.yaml +++ b/yaml-reader/tests/test.yaml @@ -1,3 +1 @@ -- it's just -- one thing -- after another +bad YAML: [ \ No newline at end of file