private void FetchValue()
{
var simpleKey = simpleKeys.Peek();
// Have we find a simple key?
if (simpleKey.IsPossible)
{
// Create the KEY token and insert it into the queue.
tokens.Insert(simpleKey.TokenNumber - tokensParsed, new Key(simpleKey.Mark, simpleKey.Mark));
// In the block context, we may need to add the BLOCK-MAPPING-START token.
RollIndent(simpleKey.LineOffset, simpleKey.TokenNumber, false, simpleKey.Mark);
// Remove the simple key.
simpleKey.IsPossible = false;
// A simple key cannot follow another simple key.
simpleKeyAllowed = false;
}
else
{
// The ':' indicator follows a complex key.
// In the block context, extra checks are required.
if (flowLevel == 0)
{
// Check if we are allowed to start a complex value.
if (!simpleKeyAllowed)
{
var mark = cursor.Mark();
throw new SyntaxErrorException(mark, mark, "Mapping values are not allowed in this context.");
}
// Add the BLOCK-MAPPING-START token if needed.
RollIndent(cursor.LineOffset, -1, false, cursor.Mark());
}
// Simple keys after ':' are allowed in the block context.
simpleKeyAllowed = flowLevel == 0;
}
// Consume the token.
var start = cursor.Mark();
Skip();
// Create the VALUE token and append it to the queue.
tokens.Enqueue(new Value(start, cursor.Mark()));
}