Skip to main content

Crate pg_parser_rs

Crate pg_parser_rs 

Source
Expand description

Public API for the pg-parser-rs crate.

This crate exposes a tree-sitter Language plus a typed AST builder for PostgreSQL-flavored SQL. For most use cases, the AST helpers are the simplest entry point.

§Examples

use pg_parser_rs::{parse_statements, Statement};

let sql = "SELECT a, b FROM t WHERE b > 1";
let statements = parse_statements(sql);
assert!(matches!(statements.first(), Some(Statement::Query(_))));

If you want diagnostics:

use pg_parser_rs::parse_statements_with_diagnostics;

let sql = "SELCT 1";
let result = parse_statements_with_diagnostics(sql);
assert!(!result.errors.is_empty());

Re-exports§

pub use ast_builder::parse_query;
pub use ast_builder::parse_query_with_diagnostics;
pub use ast_builder::parse_statements;
pub use ast_builder::parse_statements_with_diagnostics;
pub use ast::*;

Modules§

ast
ast_builder

Structs§

Language
An opaque object that defines how to parse a particular language. The code for each Language is generated by the Tree-sitter CLI.
Node
A single node within a syntax Tree.
Parser
A stateful object that this is used to produce a Tree based on some source code.
PgParser
Point
A position in a multi-line text document, in terms of rows and columns.
Range
A range of positions in a multi-line text document, both in terms of bytes and of rows and columns.
Tree
A tree that represents the syntactic structure of a source code file.

Constants§

NODE_TYPES
Returns the Tree-sitter node-types JSON used by downstream tools.

Functions§

language
parse
Parse a SQL string into a tree-sitter CST.