1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-12-27 23:43:40 +02:00
Files
ferret/pkg/parser/parser.go
Tim Voronov 24752c0f48 Updated ANTLR and other dependencies. Upgraded Go version (#796)
* Updated ANTLR and other dependencies. Upgraded Go version

* Updated unit tests

* Updated CodeQL

* Fixed linting errors

* Updated build pipeline

* Reverted refactoring of build pipeline

* Removed outdated examples from E2E tests
2025-05-07 10:50:17 -04:00

44 lines
1.1 KiB
Go

//go:generate antlr -Xexact-output-dir -o fql -package fql -visitor -Dlanguage=Go antlr/FqlLexer.g4 antlr/FqlParser.g4
package parser
import (
"github.com/antlr4-go/antlr/v4"
"github.com/MontFerret/ferret/pkg/parser/fql"
)
type Parser struct {
tree *fql.FqlParser
}
func New(query string) *Parser {
input := antlr.NewInputStream(query)
// converts tokens to upper case, so now it doesn't matter
// in which case the tokens were entered
upper := newCaseChangingStream(input, true)
lexer := fql.NewFqlLexer(upper)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
p := fql.NewFqlParser(stream)
p.BuildParseTrees = true
return &Parser{tree: p}
}
func (p *Parser) GetLiteralNames() []string {
return p.tree.GetLiteralNames()[:]
}
func (p *Parser) AddErrorListener(listener antlr.ErrorListener) {
p.tree.AddErrorListener(listener)
}
func (p *Parser) Visit(visitor fql.FqlParserVisitor) interface{} {
return visitor.VisitProgram(p.tree.Program().(*fql.ProgramContext))
}
func (p *Parser) Walk(listener fql.FqlParserListener) {
antlr.ParseTreeWalkerDefault.Walk(listener, p.tree.Program())
}