在ANTLR3中获取复合规则的lexeme

时间:2010-12-04 01:43:23

标签: java antlr antlr3

我想说的是:

rule:  (rule2 | rule3) {;}; //How can i get at this point rule2 or rule3 text?
rule2: HELLO+;
rule3: WORLD*;

我想获取rule2或rule3文本,但我得到的只是type_return,只能给我startstop

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

尝试:

rule
  :  r=(rule2 | rule3) {String txt = $r.text;}
  ;