SPPCompiler.SemanticAnalysis.Asts.Mixins.VariableLikeAst module

class SPPCompiler.SemanticAnalysis.Asts.Mixins.VariableLikeAst.VariableLikeAst

Bases: object

UNMATCHABLE_VARIABLE: Final[str] = '_UNMATCHABLE'

! A VariableLikeAst is an AST that is either a variable, or treated as one. This is limited to the LocalVariableXXX and FunctionParameterXXX classes, and provides a way to extract the named information from them. This allows for destructured named to be returned where required.

abstract property extract_names: list[Asts.IdentifierAst]

! Extract the names represented by this AST. For “let (x, y) = 123”, “(x, y)” is the local variables, and its names are “x” and “y”. Nested destructuring is supposed, so this method will be recursive. @return The list of names.

abstract property extract_name: Asts.IdentifierAst

! Extract the single name, if possible, represented by this AST for “f(a: Str)”, “a: Str” is the function parameter, and its name is “a”. When a destructure is used, there is no single name, so the placeholder “UNMATCHABLE_VARIABLE” is used.