antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

[Go] Type signature error

Open jonlundy opened this issue 10 months ago • 4 comments

Hi, the commit here: https://github.com/antlr/antlr4/commit/c96c9ccea0be86f5dbc473052893674759dcc881

the CharStream signature for GetTextFromInterval(Interval) string https://github.com/antlr/antlr4/blob/dev/runtime/Go/antlr/v4/char_stream.go#L11

seems to have missed changing the pointer for NewInputStream(data string) *InputStream https://github.com/antlr/antlr4/blob/dev/runtime/Go/antlr/v4/input_stream.go#L48

jonlundy avatar Apr 03 '24 21:04 jonlundy


func (is *InputStream) GetTextFromInterval(i Interval) string {
	return is.GetText(i.Start, i.Stop)
}
...


func (c *CommonTokenStream) GetTextFromInterval(interval Interval) string {

CharStream is an interface. Can you elaborate on what you mean?

jimidle avatar May 18 '24 16:05 jimidle

I might be hitting this. I'm following this example: https://blog.gopheracademy.com/advent-2017/parsing-with-antlr4-and-go/

And, I'm hitting this error:

cannot use is (variable of type *"github.com/antlr4-go/antlr".InputStream) as "github.com/antlr4-go/antlr/v4".CharStream value in argument to parser.NewCalcLexer: *"github.com/antlr4-go/antlr".InputStream does not implement "github.com/antlr4-go/antlr/v4".CharStream (wrong type for method GetTextFromInterval)
		have GetTextFromInterval(*"github.com/antlr4-go/antlr".Interval) string
		want GetTextFromInterval("github.com/antlr4-go/antlr/v4".Interval) string compiler[InvalidIfaceAssign](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#InvalidIfaceAssign)

AFAICT, the only difference between what it has and what it wants is the "v4" at the end.

bcparkison avatar Jul 06 '24 01:07 bcparkison

The article is out of date. please read the go README and switch to the new repo for importing the go runtime module. You also need antlr 4.13.1

jimidle avatar Jul 06 '24 14:07 jimidle

Sorry for the false alarm! I'm learning Go and Antlr at the same time, and made a silly mistake. Thanks for pointing me in the right direction!

bcparkison avatar Jul 06 '24 18:07 bcparkison