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(query.source_map()));
15//! ```
16
17#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
18
19pub mod analyze;
20pub mod bytecode;
21pub mod colors;
22pub mod compile;
23pub mod diagnostics;
24pub mod emit;
25pub mod engine;
26pub mod parser;
27pub mod query;
28pub mod type_system;
29pub mod typegen;
30
31/// Result type for analysis passes that produce both output and diagnostics.
32///
33/// Each pass returns its typed output alongside any diagnostics it collected.
34/// Fatal errors (like fuel exhaustion) use the outer `Result`.
35pub type PassResult<T> = std::result::Result<(T, Diagnostics), Error>;
36
37pub use colors::Colors;
38pub use diagnostics::{Diagnostics, DiagnosticsPrinter, Severity, Span};
39pub use query::{Query, QueryBuilder};
40pub use query::{SourceId, SourceMap};
41
42/// Errors that can occur during query parsing.
43#[derive(Debug, Clone, thiserror::Error)]
44pub enum Error {
45    /// Execution fuel exhausted (too many parser operations).
46    #[error("execution limit exceeded")]
47    ExecFuelExhausted,
48
49    /// Recursion fuel exhausted (input nested too deeply).
50    #[error("recursion limit exceeded")]
51    RecursionLimitExceeded,
52
53    #[error("query parsing failed with {} errors", .0.error_count())]
54    QueryParseError(Diagnostics),
55
56    #[error("query analysis failed with {} errors", .0.error_count())]
57    QueryAnalyzeError(Diagnostics),
58}
59
60/// Result type for query operations.
61pub type Result<T> = std::result::Result<T, Error>;