Replies: 1 comment
-
You will need to use listeners AFAICT. The method name Start() is based on the name of your top level rule. For the grammar I'm working on right now, the top level rule is called "file" and so ANTLR generates a parser method File() and I run p.File() to get my parse tree. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been trying to use Antlr4 with Golang. Either with a visitor or listener, I'm looking for an accurate example. In the code for example, I need a parse tree object on the last line (p.Start()) but that doesn't seem to exist.
#package Chicken3000
import (
"busygeeks.com/Chicken3000/Chicken3000Parser"
"github.com/antlr4-go/antlr/v4"
}
func PrepareEntityHandlers() {
}
type Chicken3000Listener struct {
*parser.BaseChicken3000Listener
}
func NewChicken3000Listener() *Chicken3000Listener {
return new(Chicken3000Listener)
}
func (l *Chicken3000Listener) EnterGameQuit(
ctx antlr.ParserRuleContext) {
}
func (l *Chicken3000Listener) ExitGameQuit(ctx *antlr.ParserRuleContext) {
}
func ParseInput(input string) {
var listener Chicken3000Listener
inputStream := antlr.NewInputStream(input)
lexer := parser.NewChicken3000Lexer(inputStream)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
p := parser.NewChicken3000Parser(stream)
antlr.ParseTreeWalker.Walk(p, listener)
}
Beta Was this translation helpful? Give feedback.
All reactions