macro processor, string juggler, script language ?

Discussion in 'Java' started by Harald, Jul 28, 2005.

  1. Harald

    Harald Guest

    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.

    --
    ---------------------+---------------------------------------------
    Harald Kirsch (@home)|
    Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software
     
    Harald, Jul 28, 2005
    #1
    1. Advertising

  2. Harald wrote:
    > 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

    --
    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/
     
    Thomas Weidenfeller, Jul 29, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shilpa
    Replies:
    8
    Views:
    560
    santosh
    Nov 21, 2006
  2. brahatha
    Replies:
    1
    Views:
    684
  3. Guru
    Replies:
    15
    Views:
    632
    James Kanze
    Jul 4, 2010
  4. Rich Morin

    ERB as a macro pre-processor?

    Rich Morin, Oct 11, 2006, in forum: Ruby
    Replies:
    3
    Views:
    143
    Rich Morin
    Oct 11, 2006
  5. Handy Gandy
    Replies:
    3
    Views:
    121
    Phlip
    Sep 7, 2010
Loading...

Share This Page