zerodds_sql_filter/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! OMG DDS content-filter-expression parser + evaluator.
5//!
6//! Safety classification: **SAFE** (a pure parser + evaluator, no data
7//! flows from external networks without caller mediation).
8//!
9//! Spec: OMG DDS 1.4 §B.2.1 "Filter expressions". The syntax is a
10//! SQL-92 subset, extended with `%N` parameter placeholders.
11//!
12//! # Current scope
13//!
14//! * Literals: string (`'...'`), integer (`i64`), float (`f64`),
15//! boolean (`TRUE`/`FALSE`).
16//! * Identifiers: dotted (`a.b.c`) — for nested field access.
17//! * Parameter placeholders: `%0`, `%1`, …
18//! * Comparison ops: `=`, `!=`, `<>`, `<`, `<=`, `>`, `>=`, `LIKE`.
19//! * Boolean ops: `AND`, `OR`, `NOT`.
20//! * Parentheses.
21//! * `LIKE` wildcards: `%` (several characters), `_` (one character).
22//!
23//! Not in the MVP: `BETWEEN ... AND`, `IN (...)`, `IS NULL`. Those
24//! follow in 3.7c.
25//!
26//! # Architecture
27//!
28//! 1. `lexer`: tokenizer. All keywords case-insensitive, string
29//! literals `'...'` with `''` escape.
30//! 2. `parser`: recursive descent with precedence climbing —
31//! `OR` < `AND` < `NOT` < comparison < atom.
32//! 3. `ast`: data types for expressions + `Value`.
33//! 4. `evaluator`: `Expr::evaluate(row, params)` → `bool`; `row`
34//! implements `RowAccess` (field lookup by name).
35//!
36//! # Usage
37//!
38//! ```
39//! use zerodds_sql_filter::{parse, Value, RowAccess};
40//! use std::collections::HashMap;
41//!
42//! struct MapRow(HashMap<String, Value>);
43//! impl RowAccess for MapRow {
44//! fn get(&self, path: &str) -> Option<Value> {
45//! self.0.get(path).cloned()
46//! }
47//! }
48//!
49//! let expr = parse("color = %0 AND x > 10").expect("parse");
50//! let row = MapRow(HashMap::from([
51//! ("color".into(), Value::String("RED".into())),
52//! ("x".into(), Value::Int(42)),
53//! ]));
54//! let params = [Value::String("RED".into())];
55//! assert_eq!(expr.evaluate(&row, ¶ms), Ok(true));
56//! ```
57
58#![cfg_attr(not(feature = "std"), no_std)]
59#![forbid(unsafe_code)]
60#![warn(missing_docs)]
61
62extern crate alloc;
63
64mod ast;
65mod evaluator;
66mod lexer;
67mod parser;
68
69pub use ast::{Expr, Value};
70pub use evaluator::{EvalError, RowAccess};
71pub use parser::{ParseError, parse};