antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

antlr 4.10.1 generates invalid go parser

Open zhiqiangxu opened this issue 3 years ago • 5 comments

Steps to reproduce:

alias antlr='java -jar ~/Downloads/antlr-4.10.1-complete.jar'
git clone https://github.com/ethereum/solidity solidity
cd solidity/docs/grammar
antlr -Dlanguage=Go -o parser SolidityLexer.g4 SolidityParser.g4

In the generated solidity_parser.go file, there're both func NewExpressionContext and type NewExpressionContext, which causes syntax error.

zhiqiangxu avatar Apr 24 '22 03:04 zhiqiangxu

Likely a "symbol conflict" in the grammar with the target.

kaby76 avatar Apr 27 '22 15:04 kaby76

Likely a "symbol conflict" in the grammar with the target.

Is it possible to automatically fix this conflict for antlr?

zhiqiangxu avatar Apr 27 '22 15:04 zhiqiangxu

Is it possible to automatically fix this conflict for antlr?

There's code to bypass these conflicts, but the list of conflicting symbols is hard-coded (at least I think it is).

Try renaming one symbol at a time in the grammar(s) with "expression" and see what fixes the problem. We typically use a trailing underscore character, e.g., "expression" => "expression_".

kaby76 avatar Apr 27 '22 16:04 kaby76

Is it possible to automatically fix this conflict for antlr?

There's code to bypass these conflicts, but the list of conflicting symbols is hard-coded (at least I think it is).

Try renaming one symbol at a time in the grammar(s) with "expression" and see what fixes the problem. We typically use a trailing underscore character, e.g., "expression" => "expression_".

Is it possible to add extra conflicting symbols from user side?

zhiqiangxu avatar Apr 28 '22 08:04 zhiqiangxu

Is it possible to add extra conflicting symbols from user side?

My understanding is that it is a static list, no way to add to the list, or add a prefix or postfix string to generated names, etc. See this discussion.

kaby76 avatar Apr 28 '22 16:04 kaby76