astx.symbol_table

astx.symbol_table

Source: packages/astx/src/astx/symbol_table.py

title: Symbol Table module for ASTx.
summary: |-

  The `SymbolTable` class offered here allows the definition
  of scopes, so the variable or function would be available in
  specifics scopes.

Classes

ScopeNodeBase

title: ScopeNodeBase is the base used for the nodes (levels) in the scope.
attributes:
  name:
    type: str
  parent:
    type: Optional[ScopeNodeBase]
  default_parent:
    type: Optional[ScopeNodeBase]
  named_expr:
    type: dict[str, NamedExpr]

ScopeNode(ScopeNodeBase)

title: Scope node organize the scope in different levels in the stack.
attributes:
  name:
    type: str
  parent:
    type: Optional[ScopeNodeBase]
  default_parent:
    type: Optional[ScopeNodeBase]
  named_expr:
    type: dict[str, NamedExpr]

Scope

title: Organize the ASTx objects according to the scope.
attributes:
  nodes:
    type: dict[int, ScopeNodeBase]
  current:
    type: Optional[ScopeNodeBase]
  previous:
    type: Optional[ScopeNodeBase]
  scope_node_class:
    type: type[ScopeNodeBase]

Methods

add(self, name: str, parent: Optional[ScopeNodeBase]=None, change_current: bool=True) -> ScopeNodeBase
title: Add a new node in the scope.
parameters:
  name:
    type: str
  parent:
    type: Optional[ScopeNodeBase]
  change_current:
    type: bool
returns:
  type: ScopeNodeBase
get_first(self) -> ScopeNodeBase
title: Get the first node in the scope.
returns:
  type: ScopeNodeBase
get_last(self) -> ScopeNodeBase
title: Get the latest node in the scope.
returns:
  type: ScopeNodeBase
destroy(self, node: ScopeNodeBase) -> None
title: Destroy the current scope.
parameters:
  node:
    type: ScopeNodeBase
set_default_parent(self, node: ScopeNodeBase) -> None
title: Set default parent for the current scope.
parameters:
  node:
    type: ScopeNodeBase

SymbolTable

title: Symbol Table for ASTx.
attributes:
  scopes:
    type: Scope

Methods

define(self, expr: NamedExpr) -> None
title: Define a new named expression inside the scoped stack.
parameters:
  expr:
    type: NamedExpr
update(self, expr: NamedExpr) -> None
title: Update the expression on the SymbolTable.
summary: |-

  It is useful mainly for updating the comment of the expression.
parameters:
  expr:
    type: NamedExpr
lookup(self, name: str) -> NamedExpr
title: Get a named expression from the scope stack.
parameters:
  name:
    type: str
returns:
  type: NamedExpr