[antlr-interest] AST rewrite: Deleting tokens

Thomas Karcher thkarcher at gmx.de
Thu Apr 17 07:36:12 PDT 2008


Hi at all,

I have the feeling I'm just missing a little piece to get what I want: I
have a tree grammar like this:

options {output=template; rewrite=true;}
[...]

block	:	^(STARTBLOCK IDENTIFIER? statements)

This represents a part of the AST where in STARTBLOCK contains already
the whole block; the parser killed the ENDBLOCK since the representation
in the AST is enough.

When the tree parser is done, I write the token stream with
tokens.ToString() to a file.

I'd like print in the generated file now only the "statements" itself,
not the STARTBLOCK or IDENTIFIER text, so I need to delete these tokens
from the RewriteTokenStream I guess - how do I do that? I experimented
with rewriting by templates:

block: ... { $st = $statements.st; }
block: ... -> printstatements(stats={$statements.text})

Either the block is gone completely (case 1) or only lines inside
statements that are rewritten by other templates appear (case 2).

Thanks for any ideas.

Thomas


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080417/92b9b231/attachment.bin 


More information about the antlr-interest mailing list