[antlr-interest] Rewrite rules - preserve internal whitespace?

Peter Nann peter.nann at vecommerce.com.au
Fri Apr 18 00:48:50 PDT 2008


Thanks Gavin.

You've clarified that at least I sort of know what's going on.  ;-)

Our resident Java Guru here has just whipped up a hand-written parser in
an afternoon that is close to doing what we want...

I think ANTLR was not quite suited to our purposes....
Maybe too many fancy features for our simple task at hand.

Or more likely, I just didn't manage to get a handle on it all quickly
enough and pare it down to just what we needed.

Cheers.

-----Original Message-----
From: Gavin Lambert [mailto:antlr at mirality.co.nz] 
Sent: Thursday, 17 April 2008 10:39 PM
To: Peter Nann; antlr-interest at antlr.org
Subject: Re: [antlr-interest] Rewrite rules - preserve internal
whitespace?

At 00:30 18/04/2008, Peter Nann wrote:
 >Rewrite rules don't maintain the whitespace (and probably not
 >comments) internal to the construct being re-written?

They will if you include them.  Otherwise they won't.

 >Will still come out:
 >"x := 1"
 >
 >Is this right?

I believe so, yes.  You're throwing away the whitespace tokens in the
input and including only those that you "care about".

 >Soooo, having rewrite rules for complex (lets say nested),
>multi-line structures is going to output probably one gigantic
>line???

Not necessarily.  It will output whatever you tell it to output.  If you
put newlines in your template, you'll get newlines in your output.  If
you include a token that contains a newline, you'll get newlines in your
output.

If you want to maintain the newlines from the input, then you'll need to
avoid filtering them out when doing the lexing/parsing.  So no hidden
channels.  (Or at least, if you do still want to put them on the hidden
channel you'll have to do something more complicated to pull them back
into your template later on.)



More information about the antlr-interest mailing list