qail_core/parser/
mod.rs

1//! QAIL Parser using nom.
2//!
3//! Parses QAIL syntax into an AST.
4//!
5//! # Syntax Overview
6//!
7//! ```text
8//! get::users:'id'email [ 'active == true, -created_at, 0..10 ]
9//! ─┬─ ─┬─ ─┬────┬──── ─────────────────┬────────────────────
10//!  │   │   │    │                      │
11//!  │   │   │    │                      └── Unified Block (filters, sorts, ranges)
12//!  │   │   │    └── Labels (columns with ')
13//!  │   │   │    └── Link (connects to table with :)
14//!  │   │   └── Table name
15//!  │   └── Gate (action with ::)
16//! ```
17
18pub mod tokens;
19pub mod columns;
20pub mod cages;
21pub mod commands;
22
23#[cfg(test)]
24mod tests;
25
26use crate::ast::*;
27use crate::error::{QailError, QailResult};
28use commands::parse_qail_cmd;
29
30/// Parse a complete QAIL query string.
31pub fn parse(input: &str) -> QailResult<QailCmd> {
32    let input = input.trim();
33    
34    match parse_qail_cmd(input) {
35        Ok(("", cmd)) => Ok(cmd),
36        Ok((remaining, _)) => Err(QailError::parse(
37            input.len() - remaining.len(),
38            format!("Unexpected trailing content: '{}'", remaining),
39        )),
40        Err(e) => Err(QailError::parse(0, format!("Parse failed: {:?}", e))),
41    }
42}