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/lamb_engine/nodes/misc.py

45 lines
1.0 KiB
Python
Raw Permalink Normal View History

2022-11-07 20:15:04 -08:00
import enum
class Direction(enum.Enum):
UP = enum.auto()
LEFT = enum.auto()
RIGHT = enum.auto()
2022-11-11 15:30:21 -08:00
2022-11-07 20:15:04 -08:00
class ReductionType(enum.Enum):
# Nothing happened. This implies that
# an expression cannot be reduced further.
NOTHING = enum.auto()
# We replaced a macro with an expression.
MACRO_EXPAND = enum.auto()
# We expanded a history reference
HIST_EXPAND = enum.auto()
# We turned a church numeral into an expression
AUTOCHURCH = enum.auto()
# We applied a function.
# This is the only type of "formal" reduction step.
FUNCTION_APPLY = enum.auto()
2022-11-11 15:30:21 -08:00
# Pretty, short names for each reduction type.
# These should all have the same length.
reduction_text = {
ReductionType.NOTHING: "N",
ReductionType.MACRO_EXPAND: "M",
ReductionType.HIST_EXPAND: "H",
ReductionType.AUTOCHURCH: "C",
ReductionType.FUNCTION_APPLY: "F",
}
2022-11-07 20:15:04 -08:00
class ReductionError(Exception):
"""
Raised when we encounter an error while reducing.
These should be caught and elegantly presented to the user.
"""
def __init__(self, msg: str):
self.msg = msg