du9826 2018-11-01 11:44
浏览 167
已采纳

Go中的AntLR4:无效的类型声明:侦听器

I generated Parser for the Go Language from Antlr4 grammar.

Grammar is here: https://raw.githubusercontent.com/antlr/grammars-v4/master/solidity/Solidity.g4

I generate parser as follows: java -jar $PWD/antlr-4.7.1-complete.jar -Dlanguage=Go -o parser syntax/Solidity.g4

The generated solidity_parser.go file has the following error whereever listener.(SolidityListener) shows up:

Invalid type assertion: listener.(SolidityListener) (non-interface type antlr.ParseTreeListener on left)

Code snippet: func (s *SourceUnitContext) EnterRule(listener antlr.ParseTreeListener) { if listenerT, ok := listener.(SolidityListener); ok { // <-- here is the error listenerT.EnterSourceUnit(s) } }

What could be the problem?

  • 写回答

1条回答 默认 最新

  • douyuai8994 2019-07-02 14:59
    关注

    can not find declaration to go

    I met the same problem. The reason is go cannot find the interface definition, just run go get github.com/antlr/antlr4/runtime/Go/antlr would solve the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!