python_ast/
scope.rs

1use std::collections::HashMap;
2use std::default::Default;
3
4/// Represents a single symbol within a scope.
5#[derive(Clone, Debug, Default)]
6pub enum Symbol {
7    SubScope(Box<Scope>),
8    Class(),
9    Variable(),
10    Const(String),
11    #[default]
12    Unknown,
13}
14
15/// Python uses LEGB scope: Local, Enclosing, Global, and Built-in.
16/// Local scope consists of local variables inside a function. Names in the local scope may change new declarations overwrite older ones.
17/// Enclosing scope is the scope of a containing function with inner/nested functions.
18/// Global is the global scope. Names within the global namespace must be unique.
19/// Built-in is basically a special scope for elements that are built into Python.
20#[derive(Clone, Debug, Default)]
21pub enum Scope {
22    #[default]
23    None,
24    Local(HashMap<String, Symbol>),
25    Global(HashMap<String, Symbol>),
26}