private ParseItemList Parse(ITextProvider text, IItemFactory itemFactory, ITokenStream stream, IParsingExecutionContext context) { var results = new ParseItemList(); while (!context.IsCancellationRequested && stream.Current.Type != TokenType.EndOfFile) { int position = stream.Position; ParseItem item; if (!itemFactory.TryCreate(null, text, stream, out item)) break; if (item.Parse(itemFactory, text, stream)) results.Add(item); // guard against infinite loop (in case token couldn't be handled) if (stream.Position == position) stream.Advance(); } // freeze everything if (!context.IsCancellationRequested) foreach (var item in results) item.Freeze(); return results; }
private ParseItemList Parse(ITextProvider text, IItemFactory itemFactory, ITokenStream stream, IParsingExecutionContext context) { var results = new ParseItemList(); while (!context.IsCancellationRequested && stream.Current.Type != TokenType.EndOfFile) { int position = stream.Position; ParseItem item; if (!itemFactory.TryCreate(null, text, stream, out item)) { break; } if (item.Parse(itemFactory, text, stream)) { results.Add(item); } // guard against infinite loop (in case token couldn't be handled) if (stream.Position == position) { stream.Advance(); } } // freeze everything if (!context.IsCancellationRequested) { foreach (var item in results) { item.Freeze(); } } return(results); }