Frame(Syntax target, Frame parent = null, HierachicalFormatter formatter = null) { Parent = parent; Formatter = parent?.Formatter ?? formatter; Target = target; LeftCache = new ValueCache<Frame>(() => new Frame(Target.Left, this)); RightCache = new ValueCache<Frame>(() => new Frame(Target.Right, this)); ItemsWithoutLeadingBreaksCache = new ValueCache<ResultItems> (GetItemsWithoutLeadingBreaks); LeadingLineBreaksCache = new ValueCache<int>(GetLeadingLineBreaksForCache); HasInnerLineBreaksCache = new ValueCache<bool>(GetHasInnerLineBreaksForCache); }
internal static Frame Create(Syntax target, HierachicalFormatter formatter) { var result = new Frame(target, formatter: formatter); return result; }
internal ResultItems Item(Frame target, int leadingLineBreaks = 0) { var tokenClass = target.Target.TokenClass; if(!IsRelevant(tokenClass)) return new ResultItems(); var leftNeighbor = target .LeftNeighbor? .Chain(item => item.LeftNeighbor) .FirstOrDefault(item => IsRelevant(item.Target.TokenClass)); var leftTokenClass = leftNeighbor?.Target.TokenClass; var indentLevel = target.IndentLevel; var token = target.Target.Token; return Item ( leftTokenClass, leadingLineBreaks, indentLevel, token, tokenClass ); }