Skip to content

future-architect/postgresql-cst-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgresql-cst-parser

Overview

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.

Key Features

  • 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.

Motivation for Development

  1. There is a lack of PostgreSQL CST (Lossless Syntax Tree) parsers that can be utilized from Rust and support a wide range of syntax.
  2. pg_query.rs is an excellent library, however, it does not construct CSTs and cannot be built for WebAssembly (wasm).

Usage

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.

Implementation

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.

License

kwlist.h, scan.l, gram.y are under the PostgreSQL License. Other files are published under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 71.0%
  • Yacc 25.2%
  • Lex 2.0%
  • C 1.6%
  • Other 0.2%