qail_core/parser/mod.rs
1//! QAIL Parser using nom.
2//!
3//! Parses QAIL v2 keyword-based syntax into an AST.
4//!
5//! # Syntax Overview
6//!
7//! ```text
8//! get users
9//! fields id, email
10//! where active = true
11//! order by created_at desc
12//! limit 10
13//! ```
14
15pub mod grammar;
16
17#[cfg(test)]
18mod tests;
19
20use crate::ast::*;
21use crate::error::{QailError, QailResult};
22
23/// Parse a complete QAIL query string (v2 syntax only).
24///
25/// Uses keyword-based syntax: `get table fields * where col = value`
26pub fn parse(input: &str) -> QailResult<QailCmd> {
27 let input = input.trim();
28
29 match grammar::parse_root(input) {
30 Ok(("", cmd)) => Ok(cmd),
31 Ok((remaining, _)) => Err(QailError::parse(
32 input.len() - remaining.len(),
33 format!("Unexpected trailing content: '{}'", remaining),
34 )),
35 Err(e) => Err(QailError::parse(0, format!("Parse failed: {:?}", e))),
36 }
37}
38