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. Native terminals
20//! retain the bounded Pratt expression and graph-pattern parsers.
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 native terminals; 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 still use upstream `sqlparser`. PGQ syntax acceptance
27//! alone does not qualify a statement family for production execution.
28//!
29//! The [SQL/PGQ specification] defines the compatibility contract. The
30//! [implementation and routing checklist] tracks the remaining parser/binder
31//! differential coverage, catalog durability, and shared query-pipeline
32//! qualification required before enabling production routing. Parser selection
33//! must be explicit by statement family, never a retry after another parser fails.
34//!
35//! [SQL/PGQ specification]: https://github.com/nowledge-co/hawdb/blob/main/docs/specs/POSTGRES_SQL_PGQ_SPEC.md
36//! [implementation and routing checklist]: https://github.com/nowledge-co/hawdb/blob/main/TODO.md#p1-postgresql-sqlpgq-compatibility
37
38mod ast;
39mod error;
40mod lexer;
41mod parser;
42/// Shared bounded token PEG machinery for HawDB syntax frontends.
43/// This implementation module is not a host-facing query API.
44#[doc(hidden)]
45pub mod peg;
46mod span;
47mod token;
48
49pub use ast::*;
50pub use error::{SyntaxError, SyntaxErrorCode};
51pub use lexer::{first_token, tokenize, tokenize_with_config, LexerConfig};
52pub use parser::{
53    parse_graph_table, parse_pgq_statement, parse_postgres_select, parse_postgres_statement,
54    parse_relational_statement,
55};
56pub use span::Span;
57pub use token::{Token, TokenKind};