[Tutor] Need help with multi-line regex identification
Tony Cappellini
tony at tcapp.com
Wed Apr 21 02:54:17 EDT 2004
I'm writing a program to give me a listing of function definitions in
source files, for an in-house programming language.
The language is very much like C (in the sense of that it has macros, which
work *almost* the same as C functions)
a macro in this language is declared as
macro MyMacroName // this is the beginning of the macro
// this is the body of the macro
integer X;
X=X+1
print"X=" X
// this is the body of the macro
emacro // this is the end of the macro
Some macro files have 20 or more macro definitions, and often there are 10
or more macro files in one program.
So it's very convenient to have a program to list all of the macros in the
source files.
With any program development, code doesn't always work the first time, and
some macros are commented out.
With this in mind, I don't want macros that are commented out to be found
by my "macro listing program"
This language uses both C and C++ style comments.
I'm new to regex's, but I've come up with the regex below to find the
beginning of a macro definition.
re.compile(r"""^ *[MACRO]+[ \t]+[a-zA-Z0-9]+""", re.IGNORECASE)
The regex below
re.compile(r"""^ *//""")
I use to find a macro definition, that has been commented out, by a
C++-style comment.
Now for the real problem
I don't want my macro lister program, to find macro definitions that are
inside of a multi-line C-style comment.
That is
/*
macro MyMacro
*/
or this
/*
macro MyMacro */
or this
/*
macro MyMacro *
/
should be IGNORED by my program, but I don't know how to do this with regex.
(or any variation of the above C-style multi-line comment)
.
Obviously, this can be done without regexs, but I think the resulting code
could be shortened significantly by
using regexs
Could someone help point me in the right direction for this ?
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040420/dfe6ec75/attachment.html
More information about the Tutor
mailing list