| tag | 85a5832f1dcd8ceed77b9076c23dbf8363250e0a | |
|---|---|---|
| tagger | Andy Grove <andygrove73@gmail.com> | Mon Sep 03 13:52:18 2018 -0600 |
| object | 9448711760239ea644c136c36b6401645c35f720 |
(cargo-release) version 0.1.2
| commit | 9448711760239ea644c136c36b6401645c35f720 | [log] [tgz] |
|---|---|---|
| author | Andy Grove <andygrove73@gmail.com> | Mon Sep 03 13:52:11 2018 -0600 |
| committer | Andy Grove <andygrove73@gmail.com> | Mon Sep 03 13:52:11 2018 -0600 |
| tree | c73e8dd11905ff948e297a7a11389447144ed46d | |
| parent | a10482c3536bd1868cda734d3ac06afe6ebc8a9a [diff] |
(cargo-release) version 0.1.2
The main goal of this project is to build a SQL lexer and parser capable of parsing ANSI SQL:2011 (or 2016 if I can get access to the specification for free).
A secondary goal is to make it easy for others to use this library as a foundation for building custom SQL parsers for vendor-specific dialects.
The current code is capable of parsing some trivial SELECT and CREATE TABLE statements.
let sql = "SELECT a, b, 123, myfunc(b) \ FROM table_1 \ WHERE a > b AND b < 100 \ ORDER BY a DESC, b"; let ast = Parser::parse_sql(sql.to_string()).unwrap(); println!("AST: {:?}", ast);
This outputs
AST: SQLSelect { projection: [SQLIdentifier("a"), SQLIdentifier("b"), SQLLiteralLong(123), SQLFunction { id: "myfunc", args: [SQLIdentifier("b")] }], relation: Some(SQLIdentifier("table_1")), selection: Some(SQLBinaryExpr { left: SQLBinaryExpr { left: SQLIdentifier("a"), op: Gt, right: SQLIdentifier("b") }, op: And, right: SQLBinaryExpr { left: SQLIdentifier("b"), op: Lt, right: SQLLiteralLong(100) } }), order_by: Some([SQLOrderBy { expr: SQLIdentifier("a"), asc: false }, SQLOrderBy { expr: SQLIdentifier("b"), asc: true }]), group_by: None, having: None, limit: None }
This parser is implemented using the Pratt Parser design, which is a top-down operator-precedence parser.
I am a fan of this design pattern over parser generators for the following reasons:
Contributors are welcome! Please see the current issues and feel free to file more!