得到一个文字的行?

时间:2015-03-31 14:31:38

标签: java antlr4

有没有办法获得_LITERAL_NAMES的行和位置?

例如:

constant returns [String typeS, int line, int pos]
     : sign number {$typeS = "integer"; $line = $number.line; $pos = $number.pos;}
     | 'true'      {$typeS = "boolean"; $line = ????; $pos = ????}
     | 'false'     {$typeS = "boolean"; $line = ????; $pos = ????}
     ;

1 个答案:

答案 0 :(得分:0)

试试这个:

constant returns [String typeS, int line, int pos]
 : sign number {$typeS = "integer"; $line = $number.line; $pos = $number.pos;}
 | t='true'    {$typeS = "boolean"; $line = $t.line; $pos = $t.pos;}
 | t='false'   {$typeS = "boolean"; $line = $t.line; $pos = $t.pos;}
 ;