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
I'm trying to use the superClass option in a lexer grammar. It works fine for a parser grammar, but for a lexer grammar, it fails at runtime with a null pointer dereference in the generated constructor NewFOOBARLexer().
For example,
type CSharpLexer struct {
*CSharpLexerBase
channelNames []string
modeNames []string
// TODO: EOF string
}
func NewCSharpLexer(input antlr.CharStream) *CSharpLexer {
l := new(CSharpLexer)
...
l.BaseLexer = antlr.NewBaseLexer(input) <<<<<< CRASHES HERE WITH NULL PTR DEREF.
...
return l
}
It crashes on l.BaseLexer = antlr.NewBaseLexer(input), specifically on the assignment to l.BaseLexer, and not on the call to the constructor antlr.NewBaseLexer(input).
Contrast this with the parser code:
type CSharpParser struct {
CSharpParserBase
}
func NewCSharpParser(input antlr.TokenStream) *CSharpParser {
this := new(CSharpParser)
...
this.BaseParser = antlr.NewBaseParser(input)
...
return this
}
This code works for the parser. The assignment to this.BaseParser works fine as it's not a null pointer.
The constructor code for the lexer fails because the type CSharpLexer struct is wrong. It defines the struct to contain*CSharpLexerBase, whereas in the parser type CSharpParser struct, the struct contains CSharpParserBase not a pointer. Changing the type struct declation for the generated lexer to CSharpLexerBase instead of *CSharpLexerBase fixes the crash, and my parser/lexer work just fine.
The problem is here-- the line erroneously contains *, whereas for the parser here, it is declared directly.
The text was updated successfully, but these errors were encountered:
I'm trying to use the superClass option in a lexer grammar. It works fine for a parser grammar, but for a lexer grammar, it fails at runtime with a null pointer dereference in the generated constructor NewFOOBARLexer().
For example,
It crashes on
l.BaseLexer = antlr.NewBaseLexer(input)
, specifically on the assignment tol.BaseLexer
, and not on the call to the constructorantlr.NewBaseLexer(input)
.Contrast this with the parser code:
This code works for the parser. The assignment to
this.BaseParser
works fine as it's not a null pointer.The constructor code for the lexer fails because the
type CSharpLexer struct
is wrong. It defines the struct to contain*CSharpLexerBase
, whereas in the parsertype CSharpParser struct
, the struct containsCSharpParserBase
not a pointer. Changing the type struct declation for the generated lexer toCSharpLexerBase
instead of*CSharpLexerBase
fixes the crash, and my parser/lexer work just fine.The problem is here-- the line erroneously contains
*
, whereas for the parser here, it is declared directly.The text was updated successfully, but these errors were encountered: