DGrok Delphi parser

What is DGrok?

The grammar: The "DGrok Delphi grammar" is the Delphi grammar that I've reverse-engineered (since CodeGear doesn't publish an official Delphi grammar — or at least, not an accurate one).

The parser: The "DGrok Delphi parser" is an open-source parser that can read Delphi code and build a syntax tree from it. The parser itself is written in C#.

The tools: The "DGrok tools" are a set of open-source tools, currently under development, for parsing Delphi source code and doing cool stuff with it: smart and lightning-fast searches, tracking down weird code constructs, refactoring, etc. See the "List of DGrok tools" below.

Downloads

Current DGrok Delphi grammar (online version; may correspond to unreleased code)

DGrok downloads (grammar, parser, tools, and all source code)

List of DGrok tools

DGrok comes with a demo app, which you can use to parse one or more directory trees, and then analyze the code looking for patterns.

Here's the current list of patterns it can look for. It's no FxCop, but it's a start.

You can also add code to look for patterns of your own. See the classes in the DGrok.Framework\Visitors directory for examples.

Project status

Currently the parser is fully capable of parsing Delphi 2007 source code, but can't read code that uses new Delphi 2009 features like string locales or generics. (The DGrok grammar doesn't document these new features either.) There's also no symbol table support yet, so the tools can't do refactorings or Find References.

More information is available in the DGrok posts on my blog.

Delphi grammar and project status

Contacting me

DGrok was written by Joe White. If you have any comments, corrections, questions, suggestions, etc., please feel free to use my contact form to get in touch with me.