// VerifySimpleKey // . Determines whether the latest simple key to be added is valid, // and if so, makes it valid. bool Scanner::VerifySimpleKey() { if(m_simpleKeys.empty()) return false; // grab top key SimpleKey key = m_simpleKeys.top(); // only validate if we're in the correct flow level if(key.flowLevel != GetFlowLevel()) return false; m_simpleKeys.pop(); bool isValid = true; // needs to be less than 1024 characters and inline if(INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024) isValid = false; // invalidate key if(isValid) key.Validate(); else key.Invalidate(); return isValid; }
// VerifySimpleKey // . Determines whether the latest simple key to be added is valid, // and if so, makes it valid. // . 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()) return m_isLastKeyValid; // grab top key SimpleKey key = m_simpleKeys.top(); // only validate if we're in the correct flow level if(key.flowLevel != m_flowLevel) { if(force) m_simpleKeys.pop(); return false; } m_simpleKeys.pop(); bool isValid = true; // needs to be followed immediately by a value if(m_flowLevel > 0 && !Exp::ValueInFlow.Matches(INPUT)) isValid = false; if(m_flowLevel == 0 && !Exp::Value.Matches(INPUT)) isValid = false; // also needs to be less than 1024 characters and inline if(INPUT.line != key.line || INPUT.pos() - key.pos > 1024) isValid = false; // invalidate key if(isValid) key.Validate(); else key.Invalidate(); // In block style, remember that we've pushed an indent for this potential simple key (if it was starting). // If it was invalid, then we need to pop it off. // Note: we're guaranteed to be popping the right one (i.e., there couldn't have been anything in // between) since keys have to be inline, and will be invalidated immediately on a newline. if(!isValid && m_flowLevel == 0) m_indents.pop(); m_isLastKeyValid = isValid; return isValid; }