gsh/evaluator/binding

The binding module defines the data structures used to track and persist variable assignments across REPL prompts.

When a user evaluates an expression like let x = 10, the evaluator parses it into a Binding record. This allows the shell to dynamically inject previous variables into the top of the generated AST for subsequent evaluations, creating the illusion of persistent local scope.

Types

Represents a single tracked variable assignment within the REPL session.

pub type Binding {
  Binding(
    kind: BindingKind,
    source: String,
    name: option.Option(String),
    pattern: String,
    value: String,
  )
}

Constructors

  • Binding(
      kind: BindingKind,
      source: String,
      name: option.Option(String),
      pattern: String,
      value: String,
    )

    Arguments

    kind

    Whether this is a let or let assert binding.

    source

    The full, raw source code of the assignment (e.g., "let x = 5").

    name

    The simple identifier name if this is a basic assignment (e.g., Some("x")). If this is a complex destructuring pattern, this will be None.

    pattern

    The left-hand side pattern of the assignment (e.g., "x" or "Ok(val)").

    value

    The right-hand side expression that produced the value (e.g., "5").

Distinguishes between a standard variable assignment and a strict pattern match.

pub type BindingKind {
  Let
  LetAssert
}

Constructors

  • Let

    A standard assignment (e.g., let x = 5).

  • LetAssert

    A strict pattern match that can crash the evaluation if it fails (e.g., let assert Ok(val) = result).

Search Document