plotnik_compiler/lib.rs
1//! Plotnik compiler: parser, analyzer, and bytecode emitter.
2//!
3//! This crate provides the compilation pipeline for Plotnik queries:
4//! - `parser` - lexer, CST, and AST construction
5//! - `analyze` - semantic analysis (symbol table, type checking, validation)
6//! - `compile` - Thompson NFA construction
7//! - `emit` - bytecode emission
8//! - `diagnostics` - error reporting
9//! - `query` - high-level Query facade
10//! - `typegen` - TypeScript type generation
11
12#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
13
14pub mod analyze;
15pub mod bytecode;
16pub mod compile;
17pub mod diagnostics;
18pub mod emit;
19pub mod parser;
20pub mod query;
21pub mod typegen;
22
23#[cfg(test)]
24pub mod test_utils;
25
26/// Result type for analysis passes that produce both output and diagnostics.
27///
28/// Each pass returns its typed output alongside any diagnostics it collected.
29/// Fatal errors (like fuel exhaustion) use the outer `Result`.
30pub type PassResult<T> = std::result::Result<(T, Diagnostics), Error>;
31
32pub use diagnostics::{Diagnostics, DiagnosticsPrinter, Severity, Span};
33pub use query::{Query, QueryBuilder};
34pub use query::{SourceId, SourceMap};
35
36/// Errors that can occur during query parsing.
37#[derive(Debug, Clone, thiserror::Error)]
38pub enum Error {
39 /// Execution fuel exhausted (too many parser operations).
40 #[error("execution limit exceeded")]
41 ExecFuelExhausted,
42
43 /// Recursion fuel exhausted (input nested too deeply).
44 #[error("recursion limit exceeded")]
45 RecursionLimitExceeded,
46
47 #[error("query parsing failed with {} errors", .0.error_count())]
48 QueryParseError(Diagnostics),
49
50 #[error("query analysis failed with {} errors", .0.error_count())]
51 QueryAnalyzeError(Diagnostics),
52}
53
54/// Result type for query operations.
55pub type Result<T> = std::result::Result<T, Error>;