irx.analysis.scopes

irx.analysis.scopes

Source: packages/irx/src/irx/analysis/scopes.py

title: Lexical scope helpers for semantic analysis.
summary: >-
  Define the lexical-scope stack used to resolve locals and detect
  redeclarations during analysis.

Classes

Scope

title: One lexical scope.
summary: >-
  Hold the local symbol table for one lexical region such as a module or
  function body.
attributes:
  kind:
    type: str
  symbols:
    type: dict[str, SemanticSymbol]

ScopeStack

title: Stack of lexical scopes.
summary: >-
  Manage nested lexical scopes for local declarations and name lookup.
attributes:
  _stack:
    type: list[Scope]

Methods

current(self) -> Scope | None
title: Return the current scope.
summary: >-
  Expose the innermost active lexical scope, if one has been pushed.
returns:
  type: Scope | None
push(self, kind: str) -> Scope
title: Push a scope.
summary: Create and activate a new lexical scope of the requested kind.
parameters:
  kind:
    type: str
returns:
  type: Scope
pop(self) -> Scope
title: Pop the current scope.
summary: >-
  Remove and return the innermost lexical scope after a block finishes
  analysis.
returns:
  type: Scope
declare(self, symbol: SemanticSymbol) -> bool
title: Declare a symbol in the current scope.
summary: >-
  Add one local symbol to the current scope, reporting whether the name
  was new there.
parameters:
  symbol:
    type: SemanticSymbol
returns:
  type: bool
resolve(self, name: str) -> SemanticSymbol | None
title: Resolve a symbol by name.
summary: >-
  Search outward from the innermost scope to find the visible local
  symbol for one name.
parameters:
  name:
    type: str
returns:
  type: SemanticSymbol | None