macro processor, string juggler, script language ?

H

Harald

Doing a lot with regular expressions --- big ones, huge ones, terrifying
monster ones --- I end up piecing together things with static final
Strings. To give you an idea of how this may look:

...
// Now piece it all together
public static final String REALLY_CUTE_STUFF =
"(" + WOOW + "[aeiou]*"
+ "|" JUNK
+ "|" BONGO
")*" + OPTSPACE

Obviously this is not easy to read, in particular on the third page of
code and with nested stuff all along.

o) I thought about using a script language (jython, jacl come to mind) and
its string manipulation facilities in external scripts to generate the
regexps. But this separates the regexps from the code and the two get
out of sync all to easy.

o) I thought about using jython or jacl interpreter objects to
interpret scripts in static final Strings, but this would entail,
say, python code within the Java source code, which isn't nice either.

o) I thought about piecing together a macro expansion facility
myself. Easy enough, but there are so many wheels around, I should not
have to invent another one.

Suggestions?

Harald.
 
T

Thomas Weidenfeller

Harald said:
o) I thought about using a script language (jython, jacl come to mind) and
its string manipulation facilities in external scripts to generate the
regexps. But this separates the regexps from the code and the two get
out of sync all to easy.

That's when a good build system comes into play. You just declare that
your code X.java depends on X.your-input-to-the-generator and if
X.your-input-to-the-generator got changed than X.java should be regenerated.
o) I thought about piecing together a macro expansion facility
myself. Easy enough, but there are so many wheels around, I should not
have to invent another one.

That's not much different from your first idea. Whether you generate
code with a code generator or with a macro-preprocessor, you still need
to keep the generated output in sync. with the input.

BTW, I would not spend any time building an own macro preprocessor.
Instead, I would use one of the existing ones, e.g. good old M4. My
choice of a scripting language (your first idea), would also be among
the more traditional ones like perl, awk, sed.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top