ANTRL: token to text in rewrite rule

Posted by Antonio on Stack Overflow See other posts from Stack Overflow or by Antonio
Published on 2012-11-20T16:56:55Z Indexed on 2012/11/20 16:59 UTC
Read the original article Hit count: 169

Filed under:
|
|

I'm building an AST using ANTLR. I want to write a production that match a this string:

${identifier}

so, in my grammar file I have:

reference
  : DOLLAR LBRACE IDENT RBRACE -> ^(NODE_VAR_REFERENCE IDENT)
;

This works fine. I'm using my own adaptor to emit tree nodes. The rewrite rule used creates for me two nodes: one for NODE_VAR_REFERENCE and one for IDENT.

What I want to do is create only one node (for NODE_VAR_REFERENCE token) and this node must have the IDENT token in his "token" field.

Is this possible using a rewrite rule? Thanks.

© Stack Overflow or respective owner

Related posts about parsing

Related posts about antlr3