mjn
mjn

Reputation: 36654

How can I find all empty try ... except blocks with GExperts grep?

In new versions of GExperts, the grep utility now supports more 'expert' expressions.

I have not yet found a way to locate empty try ... except blocks in Delphi sources using regular expressions, how could I do this with the GExperts grep tool?

Upvotes: 1

Views: 711

Answers (2)

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58441

I doubt that GExperts Regex functionality allows you to search beyond line delimiters.

If you don't mind using a component like TPerlRegEx, following code should get you started to roll your own search.

var
  emptyExceptBlock: TPerlRegEx;
  Results: TStringList;

emptyExceptBlock := TPerlRegEx.Create(nil);
emptyExceptBlock.RegEx := except\s+((//.*|/\*.*\*/|\(\*.*\*\))\s+)*end;
emptyExceptBlock.Options := [preExtended];
emptyExceptBlock.Subject := LoadFromFile('YourFile.pas');
Results := TStringList.Create;
if emptyExceptBlock.Match then begin
    repeat
        Results.Add(emptyExceptBlock.MatchedExpression);
    until not emptyExceptBlock.MatchAgain;
end;

Upvotes: 5

dummzeuch
dummzeuch

Reputation: 11217

There is a tool called Insert Auto Todo (which is not part of GExperts, I think I got it from CodeCentral) that automatically inserts todos into empty begin/end blocks. Maybe that's what you want?

Upvotes: 0

Related Questions