Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Go] Can not use BailErrorStrategy since ParseCancellationException is not implement #4603

Open
olOwOlo opened this issue Apr 23, 2024 · 1 comment

Comments

@olOwOlo
Copy link

olOwOlo commented Apr 23, 2024

  • 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/v4@v4.13.0/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/v4@v4.13.0/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.

func (p ParseCancellationException) GetMessage() string {
//TODO implement me
panic("implement me")
}

  • 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()
@jimidle
Copy link
Collaborator

jimidle commented Apr 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants