/// <summary> /// Process all the errors obtained by calling the ReadLine() function, and forward them to an array of listeners /// </summary> /// <param name="ReadLine">Delegate used to retrieve each output line</param> /// <param name="Matchers">List of matchers to run against the text</param> /// <param name="IgnorePatterns">List of patterns to ignore</param> /// <param name="Listeners">Set of listeners for processing the errors</param> /// <param name="bNoWarnings">Does not output warnings</param> static void ProcessErrors(Func <string> ReadLine, List <IErrorMatcher> Matchers, List <string> IgnorePatterns, List <IErrorListener> Listeners, bool bNoWarnings) { System.Text.RegularExpressions.Regex.CacheSize = 1000; LineBuffer Buffer = new LineBuffer(ReadLine, 50); ReadOnlyLineBuffer ReadOnlyBuffer = new ReadOnlyLineBuffer(Buffer); string FirstLine; while (Buffer.TryGetLine(0, out FirstLine)) { // Try to match an error ErrorMatch Error = null; foreach (IErrorMatcher Matcher in Matchers) { ErrorMatch NewError = Matcher.Match(ReadOnlyBuffer); if (NewError != null && (Error == null || NewError.Priority > Error.Priority)) { Error = NewError; } } // If we matched a warning and don't want it, clear it out if (Error != null && Error.Severity == ErrorSeverity.Warning && bNoWarnings) { Error = null; } // If we did match something, check if it's not negated by an ignore pattern. We typically have relatively few errors and many more ignore patterns than matchers, so it's quicker // to check them in response to an identified error than to treat them as matchers of their own. if (Error != null) { foreach (string IgnorePattern in IgnorePatterns) { if (Regex.IsMatch(Buffer[0], IgnorePattern)) { Error = null; break; } } } // Report the error to the listeners int AdvanceLines = 1; if (Error != null) { foreach (IErrorListener Listener in Listeners) { Listener.OnErrorMatch(Error); } AdvanceLines = Error.MaxLineNumber + 1 - Buffer.CurrentLineNumber; } // Move forwards Buffer.Advance(AdvanceLines); } }
public ErrorMatch(ErrorSeverity Severity, ErrorPriority Priority, string Type, ReadOnlyLineBuffer Input, int MinOffset, int MaxOffset) : this(Severity, Priority, Type, Input.CurrentLineNumber + MinOffset, Input.CurrentLineNumber + MaxOffset) { for (int Offset = MinOffset; Offset <= MaxOffset; Offset++) { Lines.Add(Input[Offset]); } }
public ErrorMatch(ErrorSeverity Severity, ErrorPriority Priority, string Type, ReadOnlyLineBuffer Input) : this(Severity, Priority, Type, Input, 0, 0) { }