private IEnumerable <UtokenBase> YieldIndentationRight(UnparsableAst self, ref BlockIndentation blockIndentation) { Unparser.tsUnparse.Debug("YieldIndentationRight"); try { // NOTE: topAncestorCacheForLeft may get updated by YieldIndentation // NOTE: ToList is needed to fully evaluate the called function, so we can catch the exception return(_YieldIndentation(self, ref blockIndentation, direction, formatYielder: this, left: false).ToList()); } catch (NonCalculatedException) { // top left node or someone in the chain is non-calculated -> defer execution Debug.Assert(blockIndentation == BlockIndentation.ToBeSet || blockIndentation.IsDeferred()); if (blockIndentation == BlockIndentation.ToBeSet) { blockIndentation = BlockIndentation.Defer(); } Debug.Assert(blockIndentation.IsDeferred()); BlockIndentation _blockIndentation = blockIndentation; return(new[] { blockIndentation.RightDeferred = new DeferredUtokens( () => _YieldIndentation(self, _blockIndentation, direction, formatYielder: this, left: false), self: self, helpMessage: "YieldIndentationRight", helpCalculatedObject: _blockIndentation ) }); } }
/// <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)); } }