/// <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)); } }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated or thrown out. /// </exception> private static IEnumerable <UtokenBase> _YieldIndentation(UnparsableAst self, BlockIndentation blockIndentationParameter, Unparser.Direction direction, FormatYielder formatYielder, bool left) { #if DEBUG BlockIndentation originalBlockIndentationParameter = blockIndentationParameter; #endif var utokens = _YieldIndentation(self, ref blockIndentationParameter, direction, formatYielder, left); #if DEBUG Debug.Assert(object.ReferenceEquals(blockIndentationParameter, originalBlockIndentationParameter), string.Format("unwanted change of blockIndentationParameter reference in _YieldIndentation ({0})", left ? "left" : "right")); #endif return(utokens); }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated or thrown out. /// </exception> private static IEnumerable <UtokenBase> _YieldBetween(UnparsableAst self, FormatYielder formatYielder) { // NOTE: topAncestorCacheForLeft may get updated by GetUsedLeftsFromTopToBottomB UnparsableAst leftObject = GetLeftTerminalLeave(self); if (leftObject != null) { InsertedUtokens insertedUtokensBetween = formatYielder._GetUtokensBetween(leftObject, self); if (insertedUtokensBetween != InsertedUtokens.None) { Unparser.tsUnparse.Debug("inserted utokens: {0}", insertedUtokensBetween); yield return(insertedUtokensBetween); } } }
private static UnparsableAst GetTopAncestorForLeft(UnparsableAst self, FormatYielder formatYielder = null) { // NOTE: topAncestorCacheForLeft will not be changed if we have no formatter, that's why we use topAncestorForLeft + the static vs. instance behavior UnparsableAst topAncestorForLeft; if (formatYielder == null || !UnparsableAst.IsCalculated(formatYielder.topAncestorCacheForLeft)) { topAncestorForLeft = CalculateTopAncestorForLeft(self); if (formatYielder != null) { formatYielder.topAncestorCacheForLeft = topAncestorForLeft; } } else { topAncestorForLeft = formatYielder.topAncestorCacheForLeft; //Unparser.tsUnparse.Debug(formatter.topAncestorCacheForLeft != CalculateTopAncestorForLeft(self), // "!!!!!!!! should be equal for {0}, but topAncestorCacheForLeft is '{1}' and calculated value is '{2}'", self, formatter.topAncestorCacheForLeft, CalculateTopAncestorForLeft(self)); Debug.Assert(formatYielder.topAncestorCacheForLeft == CalculateTopAncestorForLeft(self)); } return(topAncestorForLeft); }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated. /// </exception> private static UnparsableAst GetLeftTerminalLeave(UnparsableAst self, FormatYielder formatYielder = null) { // NOTE: topAncestorCacheForLeft will not be changed if we have no formatter, that's why we use topAncestorForLeft + the static vs. instance behavior UnparsableAst leftTerminalLeave; if (formatYielder == null || !UnparsableAst.IsCalculated(formatYielder.topAncestorCacheForLeft)) { leftTerminalLeave = CalculateLeftTerminalLeave(self, formatYielder); if (formatYielder != null) { formatYielder.leftTerminalLeaveCache = leftTerminalLeave; } } else { leftTerminalLeave = formatYielder.leftTerminalLeaveCache; //Unparser.tsUnparse.Debug(formatter.leftTerminalLeaveCache != CalculateLeftTerminalLeave(self, formatter), // "!!!!!!!! should be equal for {0}, but leftTerminalLeaveCache is '{1}' and calculated value is '{2}'", self, formatter.leftTerminalLeaveCache, CalculateLeftTerminalLeave(self, formatter)); Debug.Assert(formatYielder.leftTerminalLeaveCache == CalculateLeftTerminalLeave(self, formatYielder)); } return(leftTerminalLeave); }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated. /// </exception> private static IEnumerable <UnparsableAst> GetLeftsFromTopToBottom(UnparsableAst self, FormatYielder formatYielder = null) { UnparsableAst topAncestorForLeft = GetTopAncestorForLeft(self, formatYielder); return(topAncestorForLeft != null ? Util.RecurseStopBeforeNull(topAncestorForLeft.LeftSibling, current => current.RightMostChild) : Enumerable.Empty <UnparsableAst>()); }
private FormatYielder(FormatYielder that) { this.formatter = that.formatter; this.direction = that.direction; }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated. /// </exception> private static UnparsableAst GetLeftTerminalLeave(UnparsableAst self, FormatYielder formatYielder = null) { // NOTE: topAncestorCacheForLeft will not be changed if we have no formatter, that's why we use topAncestorForLeft + the static vs. instance behavior UnparsableAst leftTerminalLeave; if (formatYielder == null || !UnparsableAst.IsCalculated(formatYielder.topAncestorCacheForLeft)) { leftTerminalLeave = CalculateLeftTerminalLeave(self, formatYielder); if (formatYielder != null) formatYielder.leftTerminalLeaveCache = leftTerminalLeave; } else { leftTerminalLeave = formatYielder.leftTerminalLeaveCache; //Unparser.tsUnparse.Debug(formatter.leftTerminalLeaveCache != CalculateLeftTerminalLeave(self, formatter), // "!!!!!!!! should be equal for {0}, but leftTerminalLeaveCache is '{1}' and calculated value is '{2}'", self, formatter.leftTerminalLeaveCache, CalculateLeftTerminalLeave(self, formatter)); Debug.Assert(formatYielder.leftTerminalLeaveCache == CalculateLeftTerminalLeave(self, formatYielder)); } return leftTerminalLeave; }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated. /// </exception> private static IEnumerable<UnparsableAst> GetLeftsFromTopToBottom(UnparsableAst self, FormatYielder formatYielder = null) { UnparsableAst topAncestorForLeft = GetTopAncestorForLeft(self, formatYielder); return topAncestorForLeft != null ? Util.RecurseStopBeforeNull(topAncestorForLeft.LeftSibling, current => current.RightMostChild) : Enumerable.Empty<UnparsableAst>(); }
private static UnparsableAst GetTopAncestorForLeft(UnparsableAst self, FormatYielder formatYielder = null) { // NOTE: topAncestorCacheForLeft will not be changed if we have no formatter, that's why we use topAncestorForLeft + the static vs. instance behavior UnparsableAst topAncestorForLeft; if (formatYielder == null || !UnparsableAst.IsCalculated(formatYielder.topAncestorCacheForLeft)) { topAncestorForLeft = CalculateTopAncestorForLeft(self); if (formatYielder != null) formatYielder.topAncestorCacheForLeft = topAncestorForLeft; } else { topAncestorForLeft = formatYielder.topAncestorCacheForLeft; //Unparser.tsUnparse.Debug(formatter.topAncestorCacheForLeft != CalculateTopAncestorForLeft(self), // "!!!!!!!! should be equal for {0}, but topAncestorCacheForLeft is '{1}' and calculated value is '{2}'", self, formatter.topAncestorCacheForLeft, CalculateTopAncestorForLeft(self)); Debug.Assert(formatYielder.topAncestorCacheForLeft == CalculateTopAncestorForLeft(self)); } return topAncestorForLeft; }
/// <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); } }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated or thrown out. /// </exception> private static IEnumerable<UtokenBase> _YieldIndentation(UnparsableAst self, BlockIndentation blockIndentationParameter, Unparser.Direction direction, FormatYielder formatYielder, bool left) { #if DEBUG BlockIndentation originalBlockIndentationParameter = blockIndentationParameter; #endif var utokens = _YieldIndentation(self, ref blockIndentationParameter, direction, formatYielder, left); #if DEBUG Debug.Assert(object.ReferenceEquals(blockIndentationParameter, originalBlockIndentationParameter), string.Format("unwanted change of blockIndentationParameter reference in _YieldIndentation ({0})", left ? "left" : "right")); #endif return utokens; }
/// <exception cref="UnparsableAst.NonCalculatedException"> /// If topLeft is non-calculated or thrown out. /// </exception> private static IEnumerable<UtokenBase> _YieldBetween(UnparsableAst self, FormatYielder formatYielder) { // NOTE: topAncestorCacheForLeft may get updated by GetUsedLeftsFromTopToBottomB UnparsableAst leftObject = GetLeftTerminalLeave(self); if (leftObject != null) { InsertedUtokens insertedUtokensBetween = formatYielder._GetUtokensBetween(leftObject, self); if (insertedUtokensBetween != InsertedUtokens.None) { Unparser.tsUnparse.Debug("inserted utokens: {0}", insertedUtokensBetween); yield return insertedUtokensBetween; } } }
private static UnparsableAst CalculateLeftTerminalLeave(UnparsableAst self, FormatYielder formatYielder) { return GetLeftsFromTopToBottom(self, formatYielder).LastOrDefault(); }
private static UnparsableAst CalculateLeftTerminalLeave(UnparsableAst self, FormatYielder formatYielder) { return(GetLeftsFromTopToBottom(self, formatYielder).LastOrDefault()); }
internal static IEnumerable <Utoken> Cook(this IEnumerable <UtokenBase> utokens, IPostProcessHelper postProcessHelper) { return(FormatYielder.PostProcess(utokens, postProcessHelper)); }