rsnarsna
feat(lambdas): integrate ALLI-script engines and create 4 separate modular Lambda functions
ea3ef49 Download language_core/control_flow.py from Rsnarsna/auto: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/Rsnarsna/auto/resolve/main/language_core/control_flow.py
- Command line
-
hf download hf://spaces/Rsnarsna/auto/language_core/control_flow.py
-
curl -L -o control_flow.py https://huggingface.co/spaces/Rsnarsna/auto/resolve/main/language_core/control_flow.py
1.1 kB
| """ | |
| Language Core: Control Flow Constructs. | |
| Defines branches, conditions, loops, and error boundaries. | |
| """ | |
| from enum import Enum | |
| from typing import List, Any, Optional | |
| class ControlFlowType(Enum): | |
| SEQUENCE = "sequence" | |
| BRANCH = "branch" # if / elif / else | |
| LOOP = "loop" # for / while | |
| TRY_CATCH = "try_catch" # try / except / finally | |
| RETURN = "return" | |
| class ControlFlowNode: | |
| """Represents a structured control flow block.""" | |
| def __init__(self, flow_type: ControlFlowType, condition: Optional[str] = None): | |
| self.flow_type = flow_type | |
| self.condition = condition | |
| self.body: List[Any] = [] | |
| self.else_body: List[Any] = [] | |
| self.finally_body: List[Any] = [] | |
| def add_to_body(self, statement: Any): | |
| self.body.append(statement) | |
| def add_to_else(self, statement: Any): | |
| self.else_body.append(statement) | |
| def __repr__(self) -> str: | |
| if self.condition: | |
| return f"ControlFlow({self.flow_type.value}: {self.condition})" | |
| return f"ControlFlow({self.flow_type.value})" | |