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/// Result type for analysis passes that produce both output and diagnostics.
24///
25/// Each pass returns its typed output alongside any diagnostics it collected.
26/// Fatal errors (like fuel exhaustion) use the outer `Result`.
27pub type PassResult<T> = std::result::Result<(T, Diagnostics), Error>;
28
29pub use diagnostics::{Diagnostics, DiagnosticsPrinter, Severity, Span};
30pub use query::{Query, QueryBuilder};
31pub use query::{SourceId, SourceMap};
32
33/// Errors that can occur during query parsing.
34#[derive(Debug, Clone, thiserror::Error)]
35pub enum Error {
36    /// Execution fuel exhausted (too many parser operations).
37    #[error("execution limit exceeded")]
38    ExecFuelExhausted,
39
40    /// Recursion fuel exhausted (input nested too deeply).
41    #[error("recursion limit exceeded")]
42    RecursionLimitExceeded,
43
44    #[error("query parsing failed with {} errors", .0.error_count())]
45    QueryParseError(Diagnostics),
46
47    #[error("query analysis failed with {} errors", .0.error_count())]
48    QueryAnalyzeError(Diagnostics),
49}
50
51/// Result type for query operations.
52pub type Result<T> = std::result::Result<T, Error>;