Suppose I have source code like the following, which by assumption is perfectly syntactically valid:
MyType basket("woven"); // initialize statement
double x = 0; // miscellaneous code
MyType bucket("plastic") ; // another initialize statement
for(int i=0; i<324; ++i ) { cout << i << "\n"; }
/* example of a disposal statement */
MyType basket();
What I want to do is detect the statement MyType bucket("plastic"); because there is no subsequent corresponding MyType bucket(); statement.
Using Python, I constructed the following regular expression (using both the DOTALL and MULTILINE options). But there's a problem, and I don't know what it is.
(?P<stmt>MyType\s+[a-zA-Z0-9_]+)\(\s*"|'[^"']+"|'\s*\)\s*;[^(?P=stmt)]*$
Essentially, I need to know how to use a named group (like (?P=stmt>)) and check for repeats of it.