plotnik_lib/lib.rs
1//! Plotnik: Query language for tree-sitter AST with type inference.
2//!
3//! # Example
4//!
5//! ```
6//! use plotnik_lib::Query;
7//!
8//! let source = r#"
9//! Expr = [(identifier) (number)]
10//! (assignment left: (Expr) @lhs right: (Expr) @rhs)
11//! "#;
12//!
13//! let query = Query::try_from(source).expect("out of fuel");
14//! eprintln!("{}", query.diagnostics().render(source));
15//! ```
16
17#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
18
19pub mod diagnostics;
20pub mod engine;
21pub mod ir;
22pub mod parser;
23pub mod query;
24
25/// Result type for analysis passes that produce both output and diagnostics.
26///
27/// Each pass returns its typed output alongside any diagnostics it collected.
28/// Fatal errors (like fuel exhaustion) use the outer `Result`.
29pub type PassResult<T> = std::result::Result<(T, Diagnostics), Error>;
30
31pub use diagnostics::{Diagnostics, DiagnosticsPrinter, Severity};
32pub use query::{Query, UNNAMED_DEF};
33
34/// Errors that can occur during query parsing.
35#[derive(Debug, Clone, thiserror::Error)]
36pub enum Error {
37 /// Execution fuel exhausted (too many parser operations).
38 #[error("execution limit exceeded")]
39 ExecFuelExhausted,
40
41 /// Recursion fuel exhausted (input nested too deeply).
42 #[error("recursion limit exceeded")]
43 RecursionLimitExceeded,
44}
45
46/// Result type for query operations.
47pub type Result<T> = std::result::Result<T, Error>;