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.

Signature
---------------------+---------------------------------------------
Harald Kirsch (@home)|
Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software
Thomas Weidenfeller - 29 Jul 2005 08:20 GMT
> 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

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/