antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
16.73k stars 3.24k forks source link

[Go] Type signature error #4578

Open jonlundy opened 3 months ago

jonlundy commented 3 months ago

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

jimidle commented 1 month ago

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?

bcparkison commented 1 week ago

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.

jimidle commented 1 week ago

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

bcparkison commented 1 week ago

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!