public MatcherChain() { Matchers = new MyBindingList <IMatcher <IComparable> >(); RemainingLineMatcher remainingLineMatcher = new RemainingLineMatcher(); remainingLineMatcher.Name = "Message"; RemainingLineMatcher = remainingLineMatcher; Matchers.ListChanged += onMatcherListChanged; onMatcherListChanged(null, null); }
public MatcherParseResult parseLine(int lineNumber, string line) { int currentIndex = 0; int currentMatcher = 0; List <IComparable> resultValues = new List <IComparable>(); foreach (IMatcher <IComparable> matcher in Matchers) { // skip whitespace for (; currentIndex < line.Length; currentIndex++) { if (!char.IsWhiteSpace(line[currentIndex])) { break; } } IMatcherResult <IComparable> matcherResult = matcher.match(line, currentIndex); if (matcherResult == null) { LogAtom failed = new LogAtom(line, lineNumber); failed.MetaValues = resultValues; // not very sophisticated empiric method to decide if a line is a new atom or belongs to previous if (currentMatcher < MatchesNeededForAtomDetected) { // failed, not even an atom failed.MetaValues.Clear(); return(new MatcherParseResult(failed)); } else { // failed, new atom return(new MatcherParseResult(failed, false)); } } else { resultValues.Add(matcherResult.Value); currentIndex = matcherResult.NextIndex; } currentMatcher++; } // new (successful) atom resultValues.Add(RemainingLineMatcher.match(line, currentIndex).Value); LogAtom success = new LogAtom(line, lineNumber); success.MetaValues = resultValues; return(new MatcherParseResult(success, true)); }