1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-23 00:28:10 +02:00

Hello world

This commit is contained in:
Tim Voronov
2018-09-18 16:42:38 -04:00
parent c872f4565b
commit e02e861240
132 changed files with 22163 additions and 2 deletions

31
pkg/parser/parser.go Normal file
View File

@ -0,0 +1,31 @@
//go:generate antlr4 -Xexact-output-dir -o fql -package fql -visitor -Dlanguage=Go antlr/FqlLexer.g4 antlr/FqlParser.g4
package parser
import (
"github.com/MontFerret/ferret/pkg/parser/fql"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
type Parser struct {
tree *fql.FqlParser
}
func New(query string) *Parser {
input := antlr.NewInputStream(query)
lexer := fql.NewFqlLexer(input)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
p := fql.NewFqlParser(stream)
p.BuildParseTrees = true
p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
return &Parser{tree: p}
}
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))
}