Parsing text file with #include and #define directives

python at bdurham.com python at bdurham.com
Thu Apr 24 21:37:03 CEST 2008


I'm parsing a text file for a proprietary product that has the following
2 directives:

#include <somefile>
#define <name> <value>

Defined constants are referenced via <#name#> syntax.

I'm looking for a single text stream that results from processing a file
containing these directives. Even better would be an iterator(?) type
object that tracked file names and line numbers as it returns individual
lines.

Is there a Python parsing library to handle this type of task or am I
better off writing my own?

The effort to write one from scratch doesn't seem too difficult (minus
recursive file and constant loops), but I wanted to avoid re-inventing
the wheel if this type of component already exists.

Thank you,

Malcolm



More information about the Python-list mailing list