This repository has been archived on 2024-11-05. You can view files and clone it, but cannot push or open issues/pull-requests.
lamb/runstatus.py

76 lines
1.5 KiB
Python
Raw Normal View History

2022-10-21 17:55:31 -07:00
import enum
import tokens
from prompt_toolkit.formatted_text import FormattedText
class RunStatus:
"""
Base class for run status.
These are returned whenever the runner does something.
"""
pass
class MacroStatus(RunStatus):
"""
Returned when a macro is defined.
Values:
`was_rewritten`: If true, an old macro was replaced.
`macro_label`: The name of the macro we just made.
2022-10-21 19:55:15 -07:00
`macro_expr`: The expr of the macro we just made.
2022-10-21 17:55:31 -07:00
"""
def __init__(
self,
*,
was_rewritten: bool,
2022-10-21 19:55:15 -07:00
macro_label: str,
macro_expr
2022-10-21 17:55:31 -07:00
):
self.was_rewritten = was_rewritten
self.macro_label = macro_label
2022-10-21 19:55:15 -07:00
self.macro_expr = macro_expr
2022-10-21 17:55:31 -07:00
class StopReason(enum.Enum):
BETA_NORMAL = ("#FFFFFF", "β-normal form")
LOOP_DETECTED = ("#FFFF00", "loop detected")
MAX_EXCEEDED = ("#FFFF00", "too many reductions")
INTERRUPT = ("#FF0000", "user interrupt")
class ReduceStatus(RunStatus):
"""
Returned when an expression is reduced.
Values:
`reduction_count`: How many reductions were made.
`stop_reason`: Why we stopped. See `StopReason`.
"""
def __init__(
self,
*,
reduction_count: int,
stop_reason: StopReason,
result: tokens.LambdaToken
):
self.reduction_count = reduction_count
self.stop_reason = stop_reason
self.result = result
class CommandStatus(RunStatus):
"""
Returned when a command is executed.
Values:
`formatted_text`: What to print after this command is executed
"""
def __init__(
self,
*,
formatted_text: FormattedText
):
self.formatted_text = formatted_text