Create new type: map (dictionary) with all support for it
This commit is contained in:
@@ -9,6 +9,7 @@ class Type(Enum):
|
||||
INTEGER = (int, lambda x: str(x))
|
||||
STRING = (str, lambda x: x)
|
||||
LIST = (list, lambda x: f"[{', '.join([e.stringify() for e in x])}]")
|
||||
MAP = (dict, lambda x: '{' + ', '.join(f"'{k.stringify()}' -> '{v.stringify()}'" for k, v in x.items()) + '}')
|
||||
PERCENT = (float, lambda x: f"{int(x * 100)}%")
|
||||
NOTE = (Note, lambda x: x.note.name)
|
||||
TYPE = (None, lambda x: str(x.type.name.lower()))
|
||||
@@ -33,6 +34,12 @@ class Type(Enum):
|
||||
"size": Type.integer(len(value))
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def map(value):
|
||||
return Value(Type.MAP, value, {
|
||||
"size": Type.integer(len(value))
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def note(value):
|
||||
return Value(Type.NOTE, value, {
|
||||
|
||||
@@ -28,6 +28,12 @@ class Value:
|
||||
|
||||
return self
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.type == other.type and self.value == other.value
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.type) ^ hash(self.value)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.type.name}({self.value})"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user