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§
Structs§
- Language
- An opaque object that defines how to parse a particular language. The code
for each
Languageis 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
Treebased 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.