internal IEnumerable <UtokenBase> YieldBeforeComments(UnparsableAst owner, Comments comments, UnparseCommentDelegate unparseComment)
{
IList <Comment> beforeComments;
IList <Comment> beforeCommentsForFormatter;
Func <IEnumerable <Comment>, int, IEnumerable <Comment> > skipOrTake;
if (direction == Unparser.Direction.LeftToRight)
{
beforeComments = comments.Left;
beforeCommentsForFormatter = comments.Left;
skipOrTake = Enumerable.Skip;
}
else
{
beforeComments = comments.Right.ReverseOptimized();
beforeCommentsForFormatter = comments.Right;
skipOrTake = Enumerable.Take;
}
foreach (var beforeComment in beforeComments.Select((beforeComment, commentIndex) => new { Value = beforeComment, Index = commentIndex }))
{
int index;
int commentCountToSkipOrTake;
if (direction == Unparser.Direction.LeftToRight)
{
index = beforeComment.Index;
commentCountToSkipOrTake = index + 1;
}
else
{
index = beforeComments.Count - 1 - beforeComment.Index;
commentCountToSkipOrTake = index;
}
foreach (UtokenBase utoken in unparseComment(owner, beforeComment.Value))
{
yield return(utoken);
}
yield return(formatter.GetUtokensBetweenCommentAndOwner(owner, beforeComment.Value, index, beforeComments.Count, skipOrTake(beforeCommentsForFormatter, commentCountToSkipOrTake))
.SetKind(InsertedUtokens.Kind.Between)
.SetAffected(owner));
}
}