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)); }
/// <summary> /// Try to apply Matchers. Add as new atom if success, otherwise append to last atom. /// </summary> private void matchAddLine(string line, int lineIndex) { MatcherParseResult parseResult = Matchers.parseLine(lineIndex, line); if (!parseResult.isLineNewAtom) { if (Statements.Count > 0) { LogAtom last = Statements.Last(); if (last.LineNumber >= lineIndex) { throw new InvalidOperationException("Invalid line sequence in statements list."); } last.RawAdditionalLines.Add(line); markDirty(last); } else { // create emergency atom even if this is not an atom (for displaying error) LogAtom failed = parseResult.newAtom; failed.RawAdditionalLines.Add("Parsing failed! Line: " + failed.RawMetaLine); Statements.Add(failed); } } else { if (parseResult.isNewAtomParseSuccess) { Statements.Add(parseResult.newAtom); } else { LogAtom failed = parseResult.newAtom; failed.RawAdditionalLines.Add("Parsing failed! Line: " + failed.RawMetaLine); Statements.Add(failed); } } }
/// <summary> /// Mark for re-matching. /// </summary> private void markDirty(LogAtom atom) { dirty.Add(atom); }
public MatcherParseResult(LogAtom atom, bool success) { isLineNewAtom = true; isNewAtomParseSuccess = success; newAtom = atom; }
public MatcherParseResult(LogAtom atom) { isLineNewAtom = false; isNewAtomParseSuccess = false; newAtom = atom; }
public void reparseAtom(LogAtom atom) { }