kaish_kernel/interpreter.rs
1//! Interpreter module for kaish.
2//!
3//! This module provides expression evaluation, variable scope management,
4//! and the structured result type (`$?`) that every command returns.
5//!
6//! # Architecture
7//!
8//! The interpreter is built in layers:
9//!
10//! - **ExecResult**: The structured result of every command, accessible as `$?`
11//! - **Scope**: Variable bindings with nested frames and path resolution
12//! - **Evaluator**: Reduces expressions to values
13//!
14//! # Command Substitution
15//!
16//! The evaluator supports `$(pipeline)` expressions through the `Executor` trait.
17//! Higher layers (L6: Pipes & Jobs) implement this trait to provide actual
18//! command execution. For standalone expression evaluation, use `NoOpExecutor`.
19//!
20//! # Example
21//!
22//! ```
23//! use kaish_kernel::interpreter::{Scope, eval_expr};
24//! use kaish_kernel::ast::{Expr, Value};
25//!
26//! let mut scope = Scope::new();
27//! scope.set("X", Value::Int(42));
28//!
29//! let expr = Expr::VarRef(kaish_kernel::ast::VarPath::simple("X"));
30//! let result = eval_expr(&expr, &mut scope).unwrap();
31//! assert_eq!(result, Value::Int(42));
32//! ```
33
34mod control_flow;
35mod eval;
36mod result;
37mod scope;
38
39pub use control_flow::ControlFlow;
40pub use eval::{eval_expr, expand_tilde, value_to_bool, value_to_string, value_to_string_with_tilde, EvalError, EvalResult, Evaluator, Executor, NoOpExecutor};
41pub use result::{apply_output_format, json_to_value, value_to_json, EntryType, ExecResult, OutputData, OutputFormat, OutputNode};
42pub use scope::Scope;