gsh/evaluator/binding
The binding module defines the core data structures used to track, persist,
and safely shadow variable assignments across sequential REPL prompts.
When a user evaluates an expression, the AST parser extracts the assignment
into a Binding record. The shell recursively injects these records into
subsequent temporary modules to maintain stateful lexical scope.
Types
Represents a parsed and tracked variable assignment within the REPL session.
pub type Binding {
Binding(
kind: BindingKind,
source: String,
names: List(String),
pattern: String,
value: String,
)
}
Constructors
-
Binding( kind: BindingKind, source: String, names: List(String), pattern: String, value: String, )Arguments
- kind
-
The syntactical classification of the binding (
letvslet assert). - source
-
The exact, raw source string of the assignment (e.g.,
"let x = 5"). - names
-
The list of variable identifiers successfully extracted from the pattern. For simple assignments this is
["x"]. For tuple/record destructuring, it contains all bound names (e.g.,["a", "b"]). - pattern
-
The left-hand side matching pattern (e.g.,
"x","#(a, b)", or"Ok(val)"). - value
-
The right-hand side expression that yielded the bound value (e.g.,
"5").
Distinguishes between standard variable assignments and strict pattern matching.
pub type BindingKind {
Let
LetAssert
}
Constructors
-
LetA standard, infallible assignment (e.g.,
let x = 5). -
LetAssertA strict, fallible pattern match that enforces structural assertions (e.g.,
let assert Ok(val) = result).