Question

I was wondering if someone uses a generic preprocessor for manipulating text files.

The idea came up, as Java does not have a preprocessor, but I'd like to have conditional code compilation, etc.

Now, taking that idea further, I might as well use a generic preprocessor for any kind of files that need frequent editing, but all edits are in a similar manner.

Now, there's good ol' m4 which I'd like to use as I use the C-preprocessor and there is GPP, that one however, stopped being developed in 2007.

I'd like some suggestions which preprocessor is preferable, if possible, it should take directives the same way C-preprocessor takes them #define SOMETHING.

Since m4 doesn't use sigils or something, it might collide with other code, when m4 is the way to go, I'd need advice on how to prefix every directive with a sigil or a different prefix or something.

Was it helpful?

Solution

Most C/C++ compilers allow you to just run the preprocessor and save the output, and can be used on generic input. (for Visual C++, I blieve the option is /P)

But remember the preprocessors cause as many problems as they solve. The designers of both C++ and Java have tried hard to eliminate the need for using the preprocessor. For example, in Java, code like this:

if (true)
     CallThis();
else
     DoNotCallThis();

will just generate code for the CallThis() call and not generate code for the condition or the else branch. (This is not a quality of Implementation issue --- it is a requirement of the Java language definition).

OTHER TIPS

For a 'sigil', use m4's command line option -P to add prefix m4_ to all built-in m4 macros. You then have m4_define, m4_divert, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top