public static InsertedUtokens SetBehavior(this UtokenInsert utoken, Behavior behavior) { InsertedUtokens insertedUtokens = utoken; insertedUtokens.Behavior = behavior; return(insertedUtokens); }
public static InsertedUtokens SetPriority(this UtokenInsert utoken, double priority) { InsertedUtokens insertedUtokens = utoken; insertedUtokens.Priority = priority; return(insertedUtokens); }
public static InsertedUtokens SetAffected(this InsertedUtokens insertedUtokens, params UnparsableAst[] affectedUnparsableAsts) { if (insertedUtokens != null) { insertedUtokens.affectedUnparsableAsts_FOR_DEBUG = affectedUnparsableAsts; } return(insertedUtokens); }
public static InsertedUtokens SetKind(this InsertedUtokens insertedUtokens, InsertedUtokens.Kind kind) { if (insertedUtokens != null) { insertedUtokens.kind = kind; } return(insertedUtokens); }
private void _GetUtokensAround(UnparsableAst target, out InsertedUtokens leftInsertedUtokens, out InsertedUtokens rightInsertedUtokens) { formatter.GetUtokensAround(target, out leftInsertedUtokens, out rightInsertedUtokens); leftInsertedUtokens .SetKind(InsertedUtokens.Kind.Left) .SetAffected(target); rightInsertedUtokens .SetKind(InsertedUtokens.Kind.Right) .SetAffected(target); }
/// <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 bool IsNextStronger(InsertedUtokens prevInsertedUtokens, InsertedUtokens nextInsertedUtokens, Unparser.Direction direction) { int compareResult = InsertedUtokens.Compare(prevInsertedUtokens, nextInsertedUtokens); if (compareResult == 0) { if (direction == Unparser.Direction.LeftToRight) { return(prevInsertedUtokens.kind == InsertedUtokens.Kind.Right); } else { return(nextInsertedUtokens.kind != InsertedUtokens.Kind.Right); } } else { return(compareResult < 0); } }
internal IEnumerable <UtokenBase> YieldAfter(UnparsableAst self, Params @params) { Unparser.tsUnparse.Debug("YieldAfter"); InsertedUtokens insertedUtokensAfter = @params.insertedUtokensAfter; if (insertedUtokensAfter != InsertedUtokens.None) { Unparser.tsUnparse.Debug("inserted utokens: {0}", insertedUtokensAfter); yield return(insertedUtokensAfter); } BlockIndentation blockIndentation = @params.blockIndentation; if (direction == Unparser.Direction.LeftToRight) { foreach (UtokenBase utoken in YieldIndentationRight(self, blockIndentation)) { yield return(utoken); } } else { foreach (UtokenBase utoken in YieldIndentationLeft(self, blockIndentation)) { yield return(utoken); } foreach (UtokenBase utoken in YieldBetween(self)) { yield return(utoken); } } UpdateCacheOnTheFly(self, State.After); }
public Params(BlockIndentation blockIndentation, InsertedUtokens insertedUtokensAfter) { this.blockIndentation = blockIndentation; this.insertedUtokensAfter = insertedUtokensAfter; }
/* * utokens contains several InsertedUtokens "sessions" which consist of "Right", "Left" and "Between" InsertedUtokens. * A session looks like this: (Right)*((Between)?(Left)?)* * * Note that "Between" and "Left" InsertedUtokens are mixed with each other. * * "Right" InsertedUtokens are handled so that in case of equal priorities we will choose the right one. * "Between" InsertedUtokens are handled so that in case of equal priorities we will choose the left one. * "Left" InsertedUtokens are handled so that in case of equal priorities we will choose the left one. * * Since "Between" and "Left" InsertedUtokens are handled in the same way, we can handle them mixed. * * We handle the InsertedUtokens like this in order to ensure that the InsertedUtokens belonging to the * outer (in sense of structure) bnfterms always being preferred against inner bnfterms in case of equal priorities. * * InsertedUtokens belonging to the same bnfterm with equal priorities are handled so that the several kind * of InsertedUtokens have strength in descending order: Between, Left, Right * */ public static IEnumerable <UtokenBase> FilterInsertedUtokens(this IEnumerable <UtokenBase> utokens, IPostProcessHelper postProcessHelper) { InsertedUtokens prevInsertedUtokensToBeYield = null; var nonOverridableSkipThroughBuffer = new Queue <UtokenBase>(); foreach (UtokenBase utoken in utokens.Concat((UtokenBase)null)) { if (utoken is InsertedUtokens) { InsertedUtokens nextInsertedUtokens = (InsertedUtokens)utoken; var switchToNextInsertedUtokens = new Lazy <bool>(() => IsNextStronger(prevInsertedUtokensToBeYield, nextInsertedUtokens, postProcessHelper.Direction)); if (nextInsertedUtokens.Behavior == Behavior.Overridable) { prevInsertedUtokensToBeYield = switchToNextInsertedUtokens.Value ? nextInsertedUtokens : prevInsertedUtokensToBeYield; } else if (nextInsertedUtokens.Behavior == Behavior.NonOverridableSkipThrough) { if (postProcessHelper.Direction == Unparser.Direction.LeftToRight) { yield return(nextInsertedUtokens); } else { nonOverridableSkipThroughBuffer.Enqueue(nextInsertedUtokens); } } else if (nextInsertedUtokens.Behavior == Behavior.NonOverridableSeparator) { if (!switchToNextInsertedUtokens.Value) { yield return(prevInsertedUtokensToBeYield); } while (nonOverridableSkipThroughBuffer.Count > 0) { yield return(nonOverridableSkipThroughBuffer.Dequeue()); } yield return(nextInsertedUtokens); prevInsertedUtokensToBeYield = null; } } else if (utoken is UtokenControl && ((UtokenControl)utoken).IsIndent()) { // handle it as it were a NonOverridableSkipThrough if (postProcessHelper.Direction == Unparser.Direction.LeftToRight) { yield return(utoken); } else { nonOverridableSkipThroughBuffer.Enqueue(utoken); } } else { if (prevInsertedUtokensToBeYield != null) { yield return(prevInsertedUtokensToBeYield); prevInsertedUtokensToBeYield = null; } while (nonOverridableSkipThroughBuffer.Count > 0) { yield return(nonOverridableSkipThroughBuffer.Dequeue()); } if (utoken != null) { yield return(utoken); } } } }
public virtual void GetUtokensAround(UnparsableAst target, out InsertedUtokens leftInsertedUtokens, out InsertedUtokens rightInsertedUtokens) { leftInsertedUtokens = InsertedUtokens.None; rightInsertedUtokens = InsertedUtokens.None; }