ANTLR には簡単なルールがあります。
title returns [ElementVector<Element> v]
@init{
$v = new ElementVector<Element>() ;
}
: '[]'
| '[' title_args {$v.add($title_args.ele);} (',' title_args {$v = $title_args.ele ;})* ']'
;
title_args は次のとおりです。
title_args returns [Element ele]
: author {$ele = new Element("author", $author.text); }
| location {$ele = new Element("location", $location.text); }
;
コンパイルしようとすると、タイトル ルールで 127 エラーが発生します。title_args は一意でない参照です。
このWebサイトの別の同様の質問( ANTLRでリストの戻り値を処理する方法)に与えられた解決策に従いましたが、字句ルールでのみ機能するようです。
それを回避する特定の方法はありますか?
ありがとう、クリストス