1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
from renardo_lib.Patterns import Pattern, PGroup
# Constants and constant values
class const:
""" A number value that cannot be changed """
def __init__(self, value):
if isinstance(value, (list, Pattern)):
self.__class__ = Pattern
self.__init__([const(x) for x in value])
elif isinstance(value, tuple):
self.__class__ = PGroup
self.__init__([const(x) for x in value])
elif isinstance(value, PGroup):
self.__class__ = value.__class__
self.__init__([const(x) for x in value])
else:
self.value = value
def __int__(self):
return int(self.value)
def __float__(self):
return float(self.value)
def __repr__(self):
return str(self.value)
def __add__(self, other):
return self.value
def __radd__(self, other):
return self.value
def __sub__(self, other):
return self.value
def __rsub__(self, other):
return self.value
def __mul__(self, other):
return self.value
def __rmul__(self, other):
return self.value
def __div__(self, other):
return self.value
def __rdiv__(self, other):
return self.value
def __gt__(self, other):
return self.value > other
def __ge__(self, other):
return self.value >= other
def __lt__(self, other):
return self.value < other
def __le__(self, other):
return self.value <= other
def __eq__(self, other):
return self.value == other
def __ne__(self, other):
return self.value != other
class _inf(const):
def __repr__(self):
return "inf"
def __add__(self, other):
return _inf(self.value + other)
def __radd__(self, other):
return _inf(other + self.value)
def __sub__(self, other):
return _inf(self.value - other)
def __rsub__(self, other):
return _inf(other - self.value)
def __mul__(self, other):
return _inf(self.value * other)
def __rmul__(self, other):
return _inf(other * self.value)
def __div__(self, other):
return _inf(self.value / other)
def __rdiv__(self, other):
return _inf(other / self.value)
def __truediv__(self, other):
return _inf(self.value / other)
def __rtruediv__(self, other):
return _inf(other / self.value)
def __eq__(self, other):
return isinstance(other, _inf)
def __gt__(self, other):
return not isinstance(other, _inf)
def __ge__(self, other):
return True
def __lt__(self, other):
return False
def __le__(self, other):
return isinstance(other, _inf)
inf = _inf(0)
class NoneConst(const):
def __init__(self):
self.value = None
|