[antlr-interest] can't generate Parser with ecmascriptA3.g

David Holroyd dave at badgers-in-foil.co.uk
Thu Sep 28 03:58:11 PDT 2006


Can't help with your problems with the ecmascript parser, but..

On Fri, Sep 22, 2006 at 07:40:17PM +0800, Guoneng Xu wrote:
> and another question is, assume i have got the AST from the Parser,
> after altering its contents a bit, how can i output it into a .js file
> in a proper format? any JavascriptEmitter class available at this
> moment? thanks in advance!

I've done something like that for ActionScript (which is actually an
ECMAscript-like language).

My approach is to capture the entire token stream as a linked list, and
then arrange that any modifications to the AST also make the appropriate
modifications to the token stream too.

Emmiting the result is then as simple as dumping the modified token
stream.

The difficulty with this is that code modifying the AST must take great
care to make the proper changes to the token stream, including doing any
pretty printing required, etc.  I think this is worth it though, since
it allows me to preserve the formatting of the original document, which
is difficult to get from a basic pretty-printing emitter that walks the
AST (I know -- I tried that approach first).

The code is open source, if you want to see it.


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list