/// <summary>Attaches trivia to the input nodes provided.</summary> /// <param name="nodes">List of input nodes. This method calls nodes.MoveNext() /// before calling nodes.Current.</param> /// <remarks>Trailing trivia after all nodes is attached to the final node. If /// <c>nodes</c> is empty then <see cref="GetEmptyResultSet"/> is called to /// create a dummy node and attach all trivia to it.</remarks> public IEnumerator <LNode> Run(IEnumerator <LNode> nodes) { NextIndex = 0; var e = RunCore(WithIndexes(nodes), null); if (e.MoveNext()) { LNode next = e.Current.A; while (e.MoveNext()) { yield return(next); next = e.Current.A; } // Associate remaining trivia with final node if (NextIndex < SortedTrivia.Count) { next = AttachTriviaTo(next, SortedTrivia.Slice(NextIndex), TriviaLocation.TrailingExtra, null, int.MaxValue) ?? next; } yield return(next); } else { // No nodes exist var result = GetEmptyResultSet(); if (result != null) { yield return(result); } } }
private Maybe <Trivia> CurrentTrivia(out SourceRange range) { var trivia = SortedTrivia.TryGet(NextIndex); if (trivia.HasValue) { range = GetRange(trivia.Value); } else { range = default(SourceRange); } return(trivia); }