Closed mrt181 closed 4 months ago
This is a problem with the Antlr4 tool. The problem is that the tool should internally rename "base" to "base_" to avoid the "symbol conflict" in the grammar. For background, read https://github.com/antlr/antlr4/pull/3451. Although the code that was updated supposedly renames "base" as a parser or lexer symbol, it seems it doesn't rename if the name is used as an attribute.
Please raise this issue in Antlr4: https://github.com/antlr/antlr4/issues
As you discovered, the workaround is to painfully rename the offending symbol. You could use Trash to do this automatically.
02/23-05:23:10 ~/test
$ trparse SqlBase.g4 | trrename 'base,base_' | trsponge -o xxx
Using built-in parser.
CSharp 0 SqlBase.g4 success 0.0674912
Writing to xxx/SqlBase.g4
02/23-05:23:57 ~/test
$ diff xxx/SqlBase.g4 .
231c231
< | base_=primaryExpression STRUCT_FIELD_REF ASTERISK #selectStructAll
---
> | base=primaryExpression STRUCT_FIELD_REF ASTERISK #selectStructAll
331c331
< | base_=primaryExpression STRUCT_FIELD_REF fieldName=identifier #dereference
---
> | base=primaryExpression STRUCT_FIELD_REF fieldName=identifier #dereference
02/23-05:24:06 ~/test
$
I am using this file (had to add .txt to it to upload it here): SqlBase.g4.txt
This creates the SqlBaseParser with
Error CS1001 : Identifier expected
on line 7895.The field that should be referenced is on line 7097
Updating line 7895 manually to
@base
fixes the compile error.