antlr4
antlr4 copied to clipboard
[Go] Can not use BailErrorStrategy since ParseCancellationException is not implement
trafficstars
- runtime version
github.com/antlr4-go/antlr/v4 v4.13.0 - panic stack
panic: implement me [recovered]
panic: implement me
goroutine 7 [running]:
testing.tRunner.func1.2({0x79b8500, 0x7a0c5a0})
/usr/local/opt/go/libexec/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
/usr/local/opt/go/libexec/src/testing/testing.go:1634 +0x377
panic({0x79b8500?, 0x7a0c5a0?})
/usr/local/opt/go/libexec/src/runtime/panic.go:770 +0x132
github.com/antlr4-go/antlr/v4.ParseCancellationException.GetMessage(...)
/Users/me/go/pkg/mod/github.com/antlr4-go/antlr/[email protected]/errors.go:247
github.com/antlr4-go/antlr/v4.(*DefaultErrorStrategy).ReportError(0x7a114a8?, {0x7a114a8, 0xc0000580e8}, {0x7a0da70, 0x7bdfd20})
/Users/me/go/pkg/mod/github.com/antlr4-go/antlr/[email protected]/error_strategy.go:108 +0x18c
- It seems that there are still some TODO. Not sure if panic meets expectations. Does Go runtime currently support this feature? I want to fast error when there are any errors.
https://github.com/antlr/antlr4/blob/380ce4b8b1658df16ada45e1d56d5aa476052376/runtime/Go/antlr/v4/errors.go#L245-L248
- usage code
errors := NewSimpleErrorListener()
chars := antlr.NewInputStream(text)
lexer := parse.NewStringTemplateLexer(chars)
lexer.RemoveErrorListeners()
lexer.AddErrorListener(errors)
tokens := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
parser := parse.NewStringTemplateParser(tokens)
parser.SetErrorHandler(antlr.NewBailErrorStrategy())
parser.RemoveErrorListeners()
parser.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
parser.AddErrorListener(errors)
parser.T()
It does not implement this at the moment. I will take a look at it, but this strategy relies on Exceptions and came from Java. Painc might in fact be the only possible way. However, unless your grammar is suspect or your input is very very large, there may not be much advantage. I see the convenience idea though.
@parrt this can be closed as won't fix.