使用antlr4生成Go代码时遇到了符号类型冲突错误。

huangapple go评论69阅读模式
英文:

use antlr4 to generate go code get symbol type conflicts error

问题

我遵循这里的指南(https://github.com/mysql/mysql-workbench/tree/8.0/library/parsers/grammars)使用antlr生成go mysql解析器代码,但是我遇到了一些错误,如下所示:

C:\Users\moyuduo\Desktop\antlr\mysql>java org.antlr.v4.Tool -Dlanguage=Go MySQLLexer.g4

C:\Users\moyuduo\Desktop\antlr\mysql>java org.antlr.v4.Tool -Dlanguage=Go MySQLParser.g4
error(134): MySQLParser.g4:476:61: 符号类型与目标语言或运行时生成的代码冲突
error(134): MySQLParser.g4:757:18: 符号类型与目标语言或运行时生成的代码冲突
error(134): MySQLParser.g4:776:22: 符号类型与目标语言或运行时生成的代码冲突
error(134): MySQLParser.g4:1301:6: 符号类型与目标语言或运行时生成的代码冲突
error(134): MySQLParser.g4:1305:4: 符号类型与目标语言或运行时生成的代码冲突
error(134): MySQLParser.g4:1687:4: 符号类型与目标语言或运行时生成的代码冲突
...

但是使用antlr生成java代码是可以的,为什么会这样呢?有人可以帮助我吗?

英文:

I follow the guide here to use antlr generate go mysql parser code, but i get some error just as follow:

C:\Users\moyuduo\Desktop\antlr\mysql>java org.antlr.v4.Tool -Dlanguage=Go MySQLLexer.g4

C:\Users\moyuduo\Desktop\antlr\mysql>java org.antlr.v4.Tool -Dlanguage=Go MySQLParser.g4
error(134): MySQLParser.g4:476:61: symbol type conflicts with generated code in target language or runtime
error(134): MySQLParser.g4:757:18: symbol type conflicts with generated code in target language or runtime
error(134): MySQLParser.g4:776:22: symbol type conflicts with generated code in target language or runtime
error(134): MySQLParser.g4:1301:6: symbol type conflicts with generated code in target language or runtime
error(134): MySQLParser.g4:1305:4: symbol type conflicts with generated code in target language or runtime
error(134): MySQLParser.g4:1687:4: symbol type conflicts with generated code in target language or runtime
...

But use antlr to generate java code is ok, why?
Is there some one help me?

答案1

得分: 1

type是Go语言中的一个关键字。MySQLParger.g4文件中的第476行是:

AGGREGATE_SYMBOL? FUNCTION_SYMBOL udfName RETURNS_SYMBOL type = (

你需要将该行中的type更改为与Go关键字不冲突的其他名称。

我相信你会在其他报告中找到类似的情况。

对于语法的作者来说,很难避免以一种方式命名事物,以避免在所有目标语言中发生冲突,所以这样的情况会出现。

英文:

type is a keyword on Go. Line 476 in the MySQLParger.g4 file is:

AGGREGATE_SYMBOL? FUNCTION_SYMBOL udfName RETURNS_SYMBOL type = (

You’ll need to change type in that line to something that doesn’t conflict with the Go keyword.

I’m sure you’ll find similar cases in the other reports.

It’s difficult for authors of grammars to avoid naming things in such a way as to avoid conflicts in all target languages, so things like this will crop up.

huangapple
  • 本文由 发表于 2021年12月18日 19:32:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/70403065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定