Go library for parsing Tableland-compliant SQL
This is a Go library for parsing a Tableland SQL statement as defined by Tableland SQL Specification.
It uses goyacc
to generate a parser based on a given grammar and a given lexer.
With the parser, you can generate an AST from a SQL statement.
This is inspired on the xwb1989/sqlparser, with eyes on SQLite's grammar and spec.
ast, err := sqlparser.Parse("SELECT * FROM table WHERE c1 > c2")
if err != nil {
panic(err)
}
ast.PrettyPrint()
Resulting AST:
(*sqlparser.AST)({
Root: (*sqlparser.Select)({
SelectColumnList: (sqlparser.SelectColumnList) (len=1 cap=1) {
(*sqlparser.StarSelectColumn)({
TableRef: (*sqlparser.Table)(<nil>)
})
},
From: (*sqlparser.Table)({
Name: (string) (len=5) "table"
}),
Where: (*sqlparser.Where)({
Type: (string) (len=5) "where",
Expr: (*sqlparser.CmpExpr)({
Operator: (string) (len=1) ">",
Left: (*sqlparser.Column)({
Name: (string) (len=2) "c1",
TableRef: (*sqlparser.Table)(<nil>)
}),
Right: (*sqlparser.Column)({
Name: (string) (len=2) "c2",
TableRef: (*sqlparser.Table)(<nil>)
}),
Escape: (sqlparser.Expr) <nil>
})
})
})
})
To get started clone this repo.
go run golang.org/x/tools/cmd/goyacc@master -l -o yy_parser.go grammar.y
make generate-diagrams
Requires Java 8 (or higher).
Reach out with feedback and ideas:
MIT AND Apache-2.0, © 2021-2022 Tableland Network Contributors