parser generator



i need to write a utility to refactor some code.
here's what i need to do:

for every unit used in a project...
1. find a procedure/function declaration
2. search within the body of that proc for a statement matching a reg expression (or simple Pos function call will do)
3. if that procedure matches the search, then add a variable declaration to the local variable list section of that procedure.
4. repeat to 1.


I started to use CodeLens to write this utility, but CodeLens lacks certain features. for one, it doesn't appear to parse any of the body of the procedure so that i can know the starting and ending positions of the body of the procedure (e.g. begin/end pair positions).

Any help is greatly appreciated!
.