Expand description
Interpreter module for kaish.
This module provides expression evaluation, variable scope management,
and the structured result type ($?) that every command returns.
§Architecture
The interpreter is built in layers:
- ExecResult: The structured result of every command, accessible as
$? - Scope: Variable bindings with nested frames and path resolution
- Evaluator: Reduces expressions to values
§Command Substitution
The evaluator supports $(pipeline) expressions through the Executor trait.
Higher layers (L6: Pipes & Jobs) implement this trait to provide actual
command execution. For standalone expression evaluation, use NoOpExecutor.
§Example
use kaish_kernel::interpreter::{Scope, eval_expr};
use kaish_kernel::ast::{Expr, Value};
let mut scope = Scope::new();
scope.set("X", Value::Int(42));
let expr = Expr::VarRef(kaish_kernel::ast::VarPath::simple("X"));
let result = eval_expr(&expr, &mut scope).unwrap();
assert_eq!(result, Value::Int(42));Structs§
- Evaluator
- Expression evaluator.
- Exec
Result - The result of executing a command or pipeline.
- NoOp
Executor - A stub executor that always returns an error.
- Output
Data - Structured output data from a command.
- Output
Node - A node in the output tree.
- Scope
- Variable scope with nested frames and last-result tracking.
Enums§
- Control
Flow - Control flow signal from statement execution.
- Entry
Type - Entry type for rendering hints (colors, icons).
- Eval
Error - Errors that can occur during expression evaluation.
- Output
Format - Output serialization format, requested via global flags.
Traits§
- Executor
- Trait for executing pipelines (command substitution).
Functions§
- apply_
output_ format - Transform an ExecResult into the requested output format.
- eval_
expr - Convenience function to evaluate an expression with a scope.
- expand_
tilde - Expand tilde (~) to home directory.
- json_
to_ value - Convert serde_json::Value to our AST Value.
- value_
to_ bool - Convert a Value to its boolean representation.
- value_
to_ json - Convert our AST Value to serde_json::Value for serialization.
- value_
to_ string - Convert a Value to its string representation for interpolation.
- value_
to_ string_ with_ tilde - Convert a Value to its string representation, with tilde expansion for paths.
Type Aliases§
- Eval
Result - Result type for evaluation.