[antlr-interest] Pretty Printer / Beautifier with Antlr

diese.adresse.nutze.ich at nurfuerspam.de diese.adresse.nutze.ich at nurfuerspam.de
Thu Dec 29 08:17:48 PST 2005


Hi guys,

I am trying to write an pretty printer for a language I have designed. It is
a fairly simple one and the pretty printer isn't supposed to do lots of
stuff:
Actually, the only thing I'd like it to do is
- indent text
- insert / remove line breaks after certain (not all) keywords.

Due to performance criterias and this simple objective I thought I should be
able to do the pretty printing without building the whole AST. Hence I am
thinking about taking the tokens one by one from the lexer. Then I'll check
whether the token I just received is a keyword I'd like to indent / push in
a newline.
The problem I have now is that sometimes there are keywords in the middle of
an expression, and I want to indent this expression. That would mean I have
to backtrack... and that doesn't sound elegant to me.

Anyone with a better idea, e.g. a little ANTLR Parser that does the trick?

I'd appreciate your input a lot,

Travis

-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie


More information about the antlr-interest mailing list