Fix up represent() method for expressions
This commit is contained in:
parent
6f5c5c3f62
commit
d62df53703
21
ppp_ast.py
21
ppp_ast.py
@ -13,14 +13,14 @@ class TupleTypeExpr(TypeExpression):
|
||||
types: List[TypeExpression]
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return f"({', '.join([type.represent() for type in self.types])})"
|
||||
|
||||
@dataclass
|
||||
class ListTypeExpr(TypeExpression):
|
||||
type: TypeExpression
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return self.type.represent()+"[]"
|
||||
|
||||
@dataclass
|
||||
class ArrayTypeExpr(TypeExpression):
|
||||
@ -28,14 +28,14 @@ class ArrayTypeExpr(TypeExpression):
|
||||
number: int
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return self.type.represent()+f"[{self.number}]"
|
||||
|
||||
@dataclass
|
||||
class TypeName(TypeExpression):
|
||||
name: str
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return self.name
|
||||
|
||||
@dataclass
|
||||
class TypeSpecification(TypeExpression):
|
||||
@ -43,7 +43,7 @@ class TypeSpecification(TypeExpression):
|
||||
types: List[TypeExpression]
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return f'{self.type.represent()}<{', '.join([type.represent() for type in self.types])}>'
|
||||
|
||||
@dataclass
|
||||
class FunctionTypeExpr(TypeExpression):
|
||||
@ -79,6 +79,9 @@ class TypeDeclaration:
|
||||
name: str
|
||||
type: TypeExpression
|
||||
|
||||
def represent(self) -> str:
|
||||
return f"{self.name}: {self.type.represent()}"
|
||||
|
||||
@dataclass
|
||||
class StructDefinition(Statement):
|
||||
name: str
|
||||
@ -141,7 +144,7 @@ class Array(Expression):
|
||||
array: List[Expression]
|
||||
|
||||
def represent(self) -> str:
|
||||
return "["+', '.join(map(str, self.array))+"]"
|
||||
return f"[:{self.element_type.represent()}{''.join([', '+element.represent() for element in self.array])}]"
|
||||
|
||||
def precedence(self) -> int: return 13
|
||||
|
||||
@ -178,7 +181,7 @@ class TupleExpr(Expression):
|
||||
elements: List[Expression]
|
||||
|
||||
def represent(self) -> str:
|
||||
return f"([{', '.join([element.represent() for element in self.elements])}])"
|
||||
return f"({', '.join([element.represent() for element in self.elements])})"
|
||||
|
||||
def precedence(self) -> int: return 13
|
||||
|
||||
@ -200,7 +203,7 @@ class LoopComprehension(Expression):
|
||||
array: Expression
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return f"[:{self.element_type.represent()}, {self.body.represent()} for {self.variable} in {self.array.represent()}]"
|
||||
|
||||
def precedence(self) -> int: return 13
|
||||
|
||||
@ -210,7 +213,7 @@ class Lambda(Expression):
|
||||
expression: Expression
|
||||
|
||||
def represent(self) -> str:
|
||||
assert False, ("Unimplemented")
|
||||
return f"lambda {', '.join([parameter.represent() for parameter in self.parameters])} => {self.expression.represent()}"
|
||||
|
||||
def precedence(self) -> int: return 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user