Skip to main content

hawdb_sql_syntax/
lib.rs

1// Copyright 2026 Nowledge
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! HawDB-owned PostgreSQL SQL/PGQ syntax frontend.
16//!
17//! This crate owns tokens, byte spans, structured syntax errors, and syntax ASTs.
18//! Statement envelopes use a bounded token PEG with packrat memoization, composed
19//! SQL/PGQ rules, and transformation into the existing syntax AST. Expressions
20//! and graph patterns are recognized by PEG rules.
21//! Semantic binding and logical-plan lowering belong to `hawdb-sql`.
22//! The internal PEG machinery is also reused by `hawdb-cypher`, with its own
23//! lexer and PEG grammar; SQL tokenization rules do not apply to Cypher.
24//!
25//! `Database::query_sql*` selects the relational PEG entry for SELECT and EXPLAIN
26//! SELECT. Relational DDL/DML import the same PEG expression rules and lower
27//! directly into HawDB IR. PGQ syntax acceptance
28//! alone does not qualify a statement family for production execution.
29//!
30//! The [SQL/PGQ specification] defines the compatibility contract. The
31//! [implementation and routing checklist] tracks the remaining parser/binder
32//! differential coverage, catalog durability, and shared query-pipeline
33//! qualification required before enabling production routing. Parser selection
34//! must be explicit by statement family, never a retry after another parser fails.
35//!
36//! [SQL/PGQ specification]: https://github.com/nowledge-co/hawdb/blob/main/docs/specs/POSTGRES_SQL_PGQ_SPEC.md
37//! [implementation and routing checklist]: https://github.com/nowledge-co/hawdb/blob/main/TODO.md#p1-postgresql-sqlpgq-compatibility
38
39mod ast;
40mod error;
41mod lexer;
42mod parser;
43/// Shared bounded token PEG machinery for HawDB syntax frontends.
44/// This implementation module is not a host-facing query API.
45#[doc(hidden)]
46pub mod peg;
47mod span;
48mod token;
49
50pub use ast::*;
51pub use error::{SyntaxError, SyntaxErrorCode};
52pub use lexer::{first_token, tokenize, tokenize_with_config, LexerConfig};
53pub use parser::{
54    parse_graph_table, parse_pgq_statement, parse_postgres_select, parse_postgres_statement,
55    parse_relational_statement,
56};
57pub use span::Span;
58pub use token::{Token, TokenKind};