The postgresql-cst-parser
is a PostgreSQL-specific Lossless Syntax Tree (CST) parser developed in Pure Rust. This document describes the parser's features, motivation, usage, and details of its implementation.
- Automatically Generated CST Parser: Automatically generated from PostgreSQL grammar, allowing it to support a wide range of syntaxes.
- Partial Limitations: Due to some incomplete implementations in the scanner, it does not support all grammatical structures.
- There is a lack of PostgreSQL CST (Lossless Syntax Tree) parsers that can be utilized from Rust and support a wide range of syntax.
- pg_query.rs is an excellent library, however, it does not construct CSTs and cannot be built for WebAssembly (wasm).
Use it as shown in the following code examples.
let resolved_root = postgresql_cst_parser::parse("SELECT 1;");
dbg!(resolved_root);
If you would like to experience this parser in action, you can try it out directly online here. Enter your own code to see how the parser operates in real-time.
The implementation uses a modified version of PostgreSQL's scan.l and gram.y based on patches from libpg_query. scan.l
has been rewritten for Rust, and a syntax parsing table has been created based on scan.l
and gram.y
to construct the parser.
kwlist.h
, scan.l
, gram.y
are under the PostgreSQL License.
Other files are published under the MIT License.