/// <exception cref="UnparsableAst.NonCalculatedException">
/// If topLeft is non-calculated or thrown out.
/// </exception>
private static IEnumerable <UtokenBase> _YieldIndentation(UnparsableAst self, ref BlockIndentation blockIndentationParameter, Unparser.Direction direction,
FormatYielder formatYielder, bool left)
{
if (!left && direction == Unparser.Direction.RightToLeft && blockIndentationParameter.IsDeferred() && blockIndentationParameter.LeftDeferred != null)
{
/*
* We are in a right-to-left unparse and this deferred right indentation depends on a deferred left indentation,
* so let's try to calculate the deferred left indentation, which - if succeed - will change the shared blockIndentation
* object state from deferred to a valid indentation.
*
* (If the left indentation wasn't deferred then it would be calculated which means that the shared blockIndentation
* object won't be deferred.)
* */
blockIndentationParameter.LeftDeferred.CalculateUtokens();
// either CalculateUtokens succeeded, and blockIndentation is not deferred, or CalculateUtokens threw a NonCalculatedException exception
Debug.Assert(!blockIndentationParameter.IsDeferred(), "CalculateUtokens succeeded, but blockIndentation remained deferred");
}
if (blockIndentationParameter == BlockIndentation.ToBeSet || blockIndentationParameter.IsDeferred())
{
UnparsableAst leftObject = GetLeftTerminalLeave(self);
BlockIndentation blockIndentation = formatYielder._GetBlockIndentation(leftObject, self);
// NOTE: topAncestorCacheForLeft gets updated by GetUsedLeftsFromTopToBottomB
if (blockIndentation != BlockIndentation.IndentNotNeeded)
{
Unparser.tsUnparse.Debug("blockindentation {0} for leftTarget '{1}' and for target '{2}'", blockIndentation, leftObject, self);
}
Debug.Assert(!blockIndentation.IsDeferred());
if (blockIndentationParameter == BlockIndentation.ToBeSet)
{
blockIndentationParameter = blockIndentation;
}
else
{
blockIndentationParameter.CopyKindFrom(blockIndentation);
}
}
if (direction == Unparser.Direction.LeftToRight)
{
return(left
? BlockIndentationToUtokenControlBefore(blockIndentationParameter)
: BlockIndentationToUtokenControlAfter(blockIndentationParameter));
}
else
{
return(left
? BlockIndentationToUtokenControlAfter(blockIndentationParameter)
: BlockIndentationToUtokenControlBefore(blockIndentationParameter));
}
}