有没有办法获得_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 = ????}
;
答案 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;}
;