You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there! First of all, thanks for the great tool, it's quite cool and fun to use.
Lately, I've played with the ANTLR a bit while using Go as a target, and came across an interesting behavior: if the .g4 file name starts with the lowercase (as well as its grammar property value), the lexer tokens will have names that start with the lowercase letter as well (due to the filename mentioned above being used as their prefix).
While in other programming languages (like Java) this doesn't mean anything besides the code style, in Go lowercase name makes the variable private - similar to Java's private String someCoolName behavior.
This way, the tokens of the lexer become unaccessible from the outside of the lexer, which sounds wrong as the GetTokenType() function is exposed via the API of many ANTLR objects.
Changing .g4 and its grammar property name to start with the uppercase letter fixes the issue.
Steps to reproduce:
get a g4 file that starts with the lowercase - for example, calculator.g4 from the grammars-v4 repo
navigate to the folder with this file
run antlr -Dlanguage=Go -o parser calculator.g4
check the generated parser/calculator_lexer.go file in the section with constants - I got this result:
Hello there! First of all, thanks for the great tool, it's quite cool and fun to use.
Lately, I've played with the ANTLR a bit while using Go as a target, and came across an interesting behavior: if the
.g4
file name starts with the lowercase (as well as itsgrammar
property value), the lexer tokens will have names that start with the lowercase letter as well (due to the filename mentioned above being used as their prefix).While in other programming languages (like Java) this doesn't mean anything besides the code style, in Go lowercase name makes the variable private - similar to Java's
private String someCoolName
behavior.This way, the tokens of the lexer become unaccessible from the outside of the lexer, which sounds wrong as the
GetTokenType()
function is exposed via the API of many ANTLR objects.Changing
.g4
and itsgrammar
property name to start with the uppercase letter fixes the issue.Steps to reproduce:
grammars-v4
repoantlr -Dlanguage=Go -o parser calculator.g4
parser/calculator_lexer.go
file in the section with constants - I got this result:Environment:
Please, let me know whether I should provide any more details to clarify the behavior I've noticed.
The text was updated successfully, but these errors were encountered: