Skip to content

mjmbischoff/esql-go-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

ESQL (Elasticsearch Query Language) go(lang) parser

This repo publishes the golang code build in mjmbischoff/esql-check repo. Main is left empty as one shouldn't rely on 'latest' and explicitly use a version instead. Notice the @ in: go get github.com/mjmbischoff/[email protected] Check out the tags of this repo for published versions.

Example use:

package main

import (
    "fmt"
    "os"
    "github.com/antlr4-go/antlr/v4"
    "github.com/mjmbischoff/esql-go-parser/parsing"
)

type BailErrorListener struct {
    *antlr.DefaultErrorListener
}

func (l *BailErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{},
    line, column int, msg string, e antlr.RecognitionException) {
    fmt.Fprintf(os.Stderr, "Syntax error at line %d:%d - %s\n", line, column, msg)
    os.Exit(1)
}

func main() {
    if len(os.Args) != 2 {
        fmt.Println("Usage: esql-check '<query>'")
        os.Exit(1)
    }

    input := antlr.NewInputStream(os.Args[1])
    lexer := parsing.NewEsqlBaseLexer(input)
    stream := antlr.NewCommonTokenStream(lexer, 0)
    parser := parsing.NewEsqlBaseParser(stream)

    parser.RemoveErrorListeners()
    parser.AddErrorListener(&BailErrorListener{})

    parser.SingleStatement()
    fmt.Println("Input is valid ✅")
}

License

Licensed under the Elastic License 2.0 https://www.elastic.co/licensing/elastic-license

This is because we rely on the g4 anltr files under the elastic/elasticsearch repo, under the x-pack directory.

Should this not apply or anything not automatically covered under that license, then it is licensed under Apache License 2.0, https://www.apache.org/licenses/LICENSE-2.0

Notes

This repo syncs with releases once every 24h

About

ESQL (Elasticsearch Query Language) parser in go(lang)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published