Added support for FollowUp line matches
This commit is contained in:
parent
9a59bafc16
commit
685e9eafc1
13
UApp.pas
13
UApp.pas
|
@ -173,6 +173,10 @@ begin
|
||||||
begin
|
begin
|
||||||
FLogFileName := AParams;
|
FLogFileName := AParams;
|
||||||
end;
|
end;
|
||||||
|
'followup':
|
||||||
|
begin
|
||||||
|
FCurrentLineFilter.SetFollowUp(AParams);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -253,10 +257,19 @@ var
|
||||||
lineFilter: TLineFilter;
|
lineFilter: TLineFilter;
|
||||||
groupRanges: TGroupRanges;
|
groupRanges: TGroupRanges;
|
||||||
begin
|
begin
|
||||||
|
if (FCurrentLineFilter <> nil)
|
||||||
|
and (FCurrentLineFilter.FollowUpMatch(ALine, groupRanges)) then
|
||||||
|
begin
|
||||||
|
WriteContent(ALine, FCurrentLineFilter.Filters, groupRanges);
|
||||||
|
Exit;
|
||||||
|
end else
|
||||||
|
FCurrentLineFilter := nil; //We assume, nothing matched.
|
||||||
|
|
||||||
for lineFilter in FLineFilters do
|
for lineFilter in FLineFilters do
|
||||||
begin
|
begin
|
||||||
if lineFilter.Matches(ALine, groupRanges) then
|
if lineFilter.Matches(ALine, groupRanges) then
|
||||||
begin
|
begin
|
||||||
|
FCurrentLineFilter := lineFilter; //Remember the last matching filter
|
||||||
WriteContent(ALine, lineFilter.Filters, groupRanges);
|
WriteContent(ALine, lineFilter.Filters, groupRanges);
|
||||||
Break;
|
Break;
|
||||||
end;
|
end;
|
||||||
|
|
62
UFilter.pas
62
UFilter.pas
|
@ -60,9 +60,14 @@ type
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
protected
|
protected
|
||||||
FExpression: TRegExpr;
|
FExpression: TRegExpr;
|
||||||
|
FFollowUp: TRegExpr; //Used to evaluate lines belonging this the first match.
|
||||||
FFilters: TFilterList;
|
FFilters: TFilterList;
|
||||||
|
function DoMatch(AExpression: TRegExpr; ALine: String;
|
||||||
|
var GroupRanges: TGroupRanges): Boolean;
|
||||||
public
|
public
|
||||||
function Matches(ALine: String; var GroupRanges: TGroupRanges): Boolean;
|
function Matches(ALine: String; var GroupRanges: TGroupRanges): Boolean;
|
||||||
|
procedure SetFollowUp(AExpression: String);
|
||||||
|
function FollowUpMatch(ALine: String; var GroupRanges: TGroupRanges): Boolean;
|
||||||
property Filters: TFilterList read FFilters;
|
property Filters: TFilterList read FFilters;
|
||||||
end;
|
end;
|
||||||
TLineFilters = specialize TFPGObjectList<TLineFilter>;
|
TLineFilters = specialize TFPGObjectList<TLineFilter>;
|
||||||
|
@ -126,32 +131,61 @@ constructor TLineFilter.Create(AExpression: String);
|
||||||
begin
|
begin
|
||||||
FExpression := TRegExpr.Create(AExpression);
|
FExpression := TRegExpr.Create(AExpression);
|
||||||
FFilters := TFilterList.Create;
|
FFilters := TFilterList.Create;
|
||||||
|
FFollowUp := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TLineFilter.Destroy;
|
destructor TLineFilter.Destroy;
|
||||||
begin
|
begin
|
||||||
FExpression.Free;
|
FExpression.Free;
|
||||||
FFilters.Free;
|
FFilters.Free;
|
||||||
|
FFollowUp.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLineFilter.DoMatch(AExpression: TRegExpr; ALine: String;
|
||||||
|
var GroupRanges: TGroupRanges): Boolean;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := AExpression.Exec(ALine);
|
||||||
|
if Result then
|
||||||
|
begin
|
||||||
|
{$ifdef debugmatches}writeln(' Match: ', AExpression.Match[0]);{$endif}
|
||||||
|
SetLength(GroupRanges, AExpression.SubExprMatchCount + 1);
|
||||||
|
for i := 0 to AExpression.SubExprMatchCount do
|
||||||
|
begin
|
||||||
|
{$ifdef debugmatches}writeln(' [', i, ']: ', AExpression.Match[i]);{$endif}
|
||||||
|
GroupRanges[i].StartIdx := AExpression.MatchPos[i];
|
||||||
|
GroupRanges[i].EndIdx := GroupRanges[i].StartIdx + AExpression.MatchLen[i];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TLineFilter.Matches(ALine: String; var GroupRanges: TGroupRanges
|
function TLineFilter.Matches(ALine: String; var GroupRanges: TGroupRanges
|
||||||
): Boolean;
|
): Boolean;
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
Result := FExpression.Exec(ALine);
|
Result := DoMatch(FExpression, ALine, GroupRanges);
|
||||||
if Result then
|
end;
|
||||||
begin
|
|
||||||
{$ifdef debugmatches}writeln(' Match: ', FExpression.Match[0]);{$endif}
|
procedure TLineFilter.SetFollowUp(AExpression: String);
|
||||||
SetLength(GroupRanges, FExpression.SubExprMatchCount + 1);
|
begin
|
||||||
for i := 0 to FExpression.SubExprMatchCount do
|
if FFollowUp = nil then
|
||||||
begin
|
FFollowUp := TRegExpr.Create(AExpression)
|
||||||
{$ifdef debugmatches}writeln(' [', i, ']: ', FExpression.Match[i]);{$endif}
|
else
|
||||||
GroupRanges[i].StartIdx := FExpression.MatchPos[i];
|
FFollowUp.Expression := AExpression;
|
||||||
GroupRanges[i].EndIdx := GroupRanges[i].StartIdx + FExpression.MatchLen[i];
|
end;
|
||||||
end;
|
|
||||||
end;
|
{
|
||||||
|
If a FollowUp-Expression is set, we evaluate that and return the result.
|
||||||
|
If no expression is set, we simply treat that as having not matched.
|
||||||
|
}
|
||||||
|
function TLineFilter.FollowUpMatch(ALine: String; var GroupRanges: TGroupRanges
|
||||||
|
): Boolean;
|
||||||
|
begin
|
||||||
|
if FFollowUp <> nil then
|
||||||
|
Result := DoMatch(FFollowUp, ALine, GroupRanges)
|
||||||
|
else
|
||||||
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ THighlight }
|
{ THighlight }
|
||||||
|
|
Loading…
Reference in New Issue