[antlr-interest] How to combine rules into one node for an AST?

Steve Bennett stevagewp at gmail.com
Sun Nov 25 01:23:04 PST 2007


On 11/25/07, Gavin Lambert <antlr at mirality.co.nz> wrote:
> That depends on what you mean.  You can make it have a single
> subnode containing both of those rules by changing it to:
>    -> ^(MARKER ^(TEXT sometext moretext))

Yeah, I guess that's one possibility, then whatever is treating the
next stage can always treat a TEXT node as an implicit concatenate
operation.

> A single node of a tree must be a single token, so if the parser

Ah, I wasn't aware of that.

> is handed multiple tokens it will have to put them as multiple
> nodes in the tree, unless you do something fancy.  Ideally, you

Perhaps I can construct a new token manually on the fly?

> should merge as much text as you can in the lexer, although this
> isn't always possible.

Yep, in my case it's definitely not possible.

Steve


More information about the antlr-interest mailing list