public string ParseHistory(SourceCode sourceCode) { StringBuilder builder = new StringBuilder(); IEnumerable <ParsingResult> parsers = this.Parsers; while (parsers.Any()) { ParsingResult parser = parsers.Take(1).First(); IEnumerable <ParsingResult> parsersInSameLocation = parsers.TakeWhile(n => n.Location == parser.Location); parsers = parsers.Skip(parsersInSameLocation.Count()); builder.AppendLine("=========="); foreach (ParsingResult result in parsersInSameLocation) { builder.AppendLine(result.ToString()); } if (parser is SuccessfulParsingResult successfulResult) { builder.AppendLine(sourceCode.HighlightContext(successfulResult.Context)); } else if (parser is FailedParsingResult failedResult) { builder.AppendLine(sourceCode.HighlightLocation(failedResult.Location)); } else { throw new Exception("Unknown ParsingResult type"); } } return(builder.ToString()); }