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

Gavin Lambert antlr at mirality.co.nz
Thu Apr 17 05:39:08 PDT 2008


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