dsq_parser/
lib.rs

1//! dsq-parser: Parser for DSQ filter language
2//!
3//! This crate provides parsing functionality for the DSQ filter language,
4//! converting filter strings into Abstract Syntax Tree (AST) representations
5//! using the nom parser combinator library.
6//!
7//! # Features
8//!
9//! - **Complete DSQ Syntax Support**: Parses all DSQ filter language constructs
10//! - **Fast Parsing**: Uses nom for high-performance parsing
11//! - **Comprehensive Error Reporting**: Detailed error messages with position information
12//! - **AST Generation**: Produces structured AST for further processing
13//!
14//! # Quick Start
15//!
16//! ```rust
17//! use dsq_parser::{FilterParser, Filter};
18//!
19//! let parser = FilterParser::new();
20//! let filter: Filter = parser.parse(".name | length")?;
21//!
22//! // Access the parsed AST
23//! match &filter.expr {
24//!     dsq_parser::Expr::Pipeline(exprs) => {
25//!         println!("Pipeline with {} expressions", exprs.len());
26//!     }
27//!     _ => {}
28//! }
29//! # Ok::<(), dsq_parser::ParseError>(())
30//! ```
31//!
32//! # Supported Syntax
33//!
34//! The parser supports the full DSQ filter language including:
35//!
36//! - **Identity and field access**: `.`, `.field`, `.field.subfield`
37//! - **Array operations**: `.[0]`, `.[1:5]`, `.[]`
38//! - **Function calls**: `length`, `map(select(.age > 30))`
39//! - **Arithmetic**: `+`, `-`, `*`, `/`
40//! - **Comparisons**: `>`, `<`, `==`, `!=`, `>=`, `<=`
41//! - **Logical operations**: `and`, `or`, `not`
42//! - **Object/array construction**: `{name, age}`, `[1, 2, 3]`
43//! - **Pipelines**: `expr1 | expr2 | expr3`
44//! - **Assignment**: `. += value`
45//!
46//! # Error Handling
47//!
48//! Parse errors include position information and expected tokens:
49//!
50//! ```rust
51//! use dsq_parser::{FilterParser, ParseError};
52//!
53//! let parser = FilterParser::new();
54//! match parser.parse("invalid syntax +++") {
55//!     Ok(_) => {}
56//!     Err(ParseError::UnexpectedToken { found, position, .. }) => {
57//!         eprintln!("Unexpected '{}' at position {}", found, position);
58//!     }
59//!     Err(e) => eprintln!("Parse error: {}", e),
60//! }
61//! ```
62
63pub mod ast;
64pub mod error;
65mod parser;
66#[cfg(test)]
67mod tests;
68
69// Re-export main types
70pub use ast::*;
71pub use error::*;
72pub use parser::*;
73
74// Re-export shared types
75pub use dsq_shared::VERSION;