Sign in to follow this  
alnite

Generic preprocessor tools

Recommended Posts

Some languages are blessed with preprocessor directives, but there are other languages that don't have them for various reasons.

So then my question is this: Is there a generic preprocessor tools out there where you can inject a few rules, process any text files, and output the result to new text files.

If the file was a Java source code, and DEBUG was set to false, it would preprocess them like this:
[code]
//#if DEBUG
int var = 10 + debugValue;
//#else
int var = 10;
//#endif

Output:
//#if DEBUG
// int var = 10 + debugValue;
//#else
int var = 10;
//#endif
[/code]

If it was Python:
[code]
##if DEBUG
var = 10 + debugValue
##else
var = 10;
##endif

Output:
##if DEBUG
# var = 10 + debugValue
##else
var = 10;
##endif
[/code]

And as you can see, you can extend this to any programming languages or scripts (HTML, CSS, bash, anything) that don't support preprocessor directives natively but support comments. Alas, I can't find any good tools that can do this seemingly-straightforward task properly. Edited by alnite

Share this post


Link to post
Share on other sites
The C preprocessor will do that. It's almost universally available as a separate phase of the compiler or as a separate executable entirely. The C preprocessor has no clue about the C (or C++, or FORTRAN, or Java) language proper.

There have been many systems that leverage the C preprocessor to enhance other languages.

Share this post


Link to post
Share on other sites
I heard M4 and saw some open source projects use it
[url="http://en.wikipedia.org/wiki/M4_%28computer_language%29"]http://en.wikipedia.org/wiki/M4_%28computer_language%29[/url]
I didn't use it before.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this