Home > Software design >  use antlr4 to generate go code get symbol type conflicts error
use antlr4 to generate go code get symbol type conflicts error

Time:12-19

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?

CodePudding user response:

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.

  • Related