Skip to content

Latest commit

 

History

History
99 lines (74 loc) · 2.84 KB

README.md

File metadata and controls

99 lines (74 loc) · 2.84 KB

Tableland SQL Parser

Review Test Release standard-readme compliant

Go library for parsing Tableland-compliant SQL

Table of Contents

Background

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.

Usage

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>
   })
  })
 })
})

Contributing

To get started clone this repo.

Generating the parser

go run golang.org/x/tools/cmd/goyacc@master -l -o yy_parser.go grammar.y

Generating syntax diagrams

make generate-diagrams 

Requires Java 8 (or higher).

Feedback

Reach out with feedback and ideas:

License

MIT AND Apache-2.0, © 2021-2022 Tableland Network Contributors