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
There is currently no constructor support for superclasses from the generated lexer/parser classes.
Without this, the initial values of a superclass instance can only be set in individually way.
Here is a short example for a lexer implementation:
...
type PythonLexerBase struct {
*antlr.BaseLexer
...
}
// go constructor for the superclass
// unfortunately this function is not called from the generated lexer
func NewPythonLexerBase(input antlr.CharStream) *PythonLexerBase {
plb := new(PythonLexerBase)
plb.BaseLexer = antlr.NewBaseLexer(input)
...
return plb
}
...
current generated lexer:
...
type PythonLexer struct {
PythonLexerBase
...
}
...
func NewPythonLexer(input antlr.CharStream) *PythonLexer {
...
l := new(PythonLexer)
l.BaseLexer = antlr.NewBaseLexer(input) // **** there is no constructor call for the superclass
...
return l
}
...
suggested generated lexer:
...
type PythonLexer struct {
*PythonLexerBase // **** by pointer
...
}
...
func NewPythonLexer(input antlr.CharStream) *PythonLexer {
...
l := new(PythonLexer)
l.PythonLexerBase = NewPythonLexerBase(input) // **** constructor call for the superclass
...
return l
}
...
I think this suggestion follows the practices of the Go language and those common in other ANTLR target languages.
The generated parser class should be created in the same way.
The text was updated successfully, but these errors were encountered:
RobEin
changed the title
Missing constructor call to the superclass of the generated parser or lexer
Go target: missing constructor call to the superclass of the generated parser or lexer
May 23, 2024
Thanks for looking at a few issues Robert. I have some big changes coming through this weekend, including generic walkers, after which cI will look at your PRs. I may already have addressed some of them I think
There is currently no constructor support for superclasses from the generated lexer/parser classes.
Without this, the initial values of a superclass instance can only be set in individually way.
Here is a short example for a lexer implementation:
my PythonLexer.g4:
my PythonLexerBase superclass:
current generated lexer:
suggested generated lexer:
I think this suggestion follows the practices of the Go language and those common in other ANTLR target languages.
The generated parser class should be created in the same way.
similar issue: #3446
The text was updated successfully, but these errors were encountered: