Skip to main content

Module interpreter

Module interpreter 

Source
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.
ExecResult
The result of executing a command or pipeline.
NoOpExecutor
A stub executor that always returns an error.
OutputData
Structured output data from a command.
OutputNode
A node in the output tree.
Scope
Variable scope with nested frames and last-result tracking.

Enums§

ControlFlow
Control flow signal from statement execution.
EntryType
Entry type for rendering hints (colors, icons).
EvalError
Errors that can occur during expression evaluation.
OutputFormat
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§

EvalResult
Result type for evaluation.