ANTLR warnings are printed to os.Stderr. Hence, what you could do is to redirect Stderr, capture all warnings, and decide what to do with them.
Of course, this means your program can not print out anything to Stderr during the parse.
Pseudocode, just to get the gist.
// redirect stdout - antlr runtime prints to STDOUT on error
outStream := make(chan string)
stderr := os.Stdout
r, w, err := os.Pipe()
if err != nil {
return err
}
os.Stderr = w
// capture stderr
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outStream <- buf.String()
}()
// run parse with stdout redirected
go func() {
// ANTLR can, and WILL panic in a pythonic fashion!
defer func() {
if r := recover(); r != nil {
listener.err = errors.Append(listener.err, errors.E(r.(string)).WithOperation("ParseString"))
}
}()
stream := antlr.NewInputStream(ddl)
lexer := parser.NewTeradataStatementLexer(stream)
tokenStream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
prsr := parser.NewTeradataStatementParser(tokenStream)
antlr.ParseTreeWalkerDefault.Walk(&listener, prsr.Program())
w.Close() // close redirected stdout
os.Stderr = stderr // redirect to normal stdout
}()
// capture stdout and check for errors
parseStdout := <-outStream
if parseStdout != "" {
// non empty stderr, handle errors reported by ANTLR
}