fix!: remove union type
This commit is contained in:
@@ -111,10 +111,6 @@ class ConstraintType:
|
||||
constraint: Expr
|
||||
|
||||
|
||||
class UnionType:
|
||||
types: list[Type]
|
||||
|
||||
|
||||
class ComplexType:
|
||||
properties: list[PropertyStmt]
|
||||
|
||||
|
||||
@@ -228,9 +228,6 @@ class Type(ABC):
|
||||
@abstractmethod
|
||||
def visit_constraint_type(self, type: ConstraintType) -> T: ...
|
||||
|
||||
@abstractmethod
|
||||
def visit_union_type(self, type: UnionType) -> T: ...
|
||||
|
||||
@abstractmethod
|
||||
def visit_complex_type(self, type: ComplexType) -> T: ...
|
||||
|
||||
@@ -261,14 +258,6 @@ class ConstraintType(Type):
|
||||
return visitor.visit_constraint_type(self)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UnionType(Type):
|
||||
types: list[Type]
|
||||
|
||||
def accept(self, visitor: Type.Visitor[T]) -> T:
|
||||
return visitor.visit_union_type(self)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ComplexType(Type):
|
||||
properties: list[PropertyStmt]
|
||||
|
||||
@@ -252,17 +252,6 @@ class MidasAstPrinter(
|
||||
with self._child_level(single=True):
|
||||
type.constraint.accept(self)
|
||||
|
||||
def visit_union_type(self, type: m.UnionType) -> None:
|
||||
self._write_line("UnionType")
|
||||
with self._child_level():
|
||||
self._write_line("types", last=True)
|
||||
with self._child_level():
|
||||
for i, type_ in enumerate(type.types):
|
||||
self._idx = i
|
||||
if i == len(type.types) - 1:
|
||||
self._mark_last()
|
||||
type_.accept(self)
|
||||
|
||||
def visit_complex_type(self, type: m.ComplexType) -> None:
|
||||
self._write_line("ComplexType")
|
||||
with self._child_level():
|
||||
@@ -379,10 +368,6 @@ class MidasPrinter(m.Expr.Visitor[str], m.Stmt.Visitor[str], m.Type.Visitor[str]
|
||||
res += " where " + type.constraint.accept(self)
|
||||
return res
|
||||
|
||||
def visit_union_type(self, type: m.UnionType) -> str:
|
||||
types: list[str] = [type_.accept(self) for type_ in type.types]
|
||||
return " | ".join(types)
|
||||
|
||||
def visit_complex_type(self, type: m.ComplexType) -> str:
|
||||
res: str = "{\n"
|
||||
self.level += 1
|
||||
|
||||
@@ -44,11 +44,4 @@ class ComplexType:
|
||||
properties: dict[str, Type]
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class UnionType:
|
||||
alternatives: list[Type]
|
||||
|
||||
|
||||
Type = (
|
||||
BaseType | AliasType | UnknownType | UnitType | Function | ComplexType | UnionType
|
||||
)
|
||||
Type = BaseType | AliasType | UnknownType | UnitType | Function | ComplexType
|
||||
|
||||
@@ -294,11 +294,6 @@ class MidasHighlighter(
|
||||
type.type.accept(self)
|
||||
type.constraint.accept(self)
|
||||
|
||||
def visit_union_type(self, type: m.UnionType) -> None:
|
||||
self.wrap(type, "union-type")
|
||||
for type_ in type.types:
|
||||
type_.accept(self)
|
||||
|
||||
def visit_complex_type(self, type: m.ComplexType) -> None:
|
||||
self.wrap(type, "complex-type")
|
||||
for prop in type.properties:
|
||||
|
||||
@@ -8,7 +8,6 @@ span {
|
||||
&.named-type,
|
||||
&.generic-type,
|
||||
&.constraint-type,
|
||||
&.union-type,
|
||||
&.complex-type {
|
||||
--col: 150, 150, 150;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ class MidasLexer(Lexer):
|
||||
self.add_token(TokenType.LEFT_BRACE)
|
||||
case "}":
|
||||
self.add_token(TokenType.RIGHT_BRACE)
|
||||
case "|":
|
||||
self.add_token(TokenType.PIPE)
|
||||
case "<":
|
||||
self.add_token(
|
||||
TokenType.LESS_EQUAL if self.match("=") else TokenType.LESS
|
||||
|
||||
@@ -23,7 +23,6 @@ class TokenType(Enum):
|
||||
AND = auto()
|
||||
QMARK = auto()
|
||||
DOT = auto()
|
||||
PIPE = auto()
|
||||
|
||||
# Operators
|
||||
# PLUS = auto()
|
||||
|
||||
@@ -20,7 +20,6 @@ from midas.ast.midas import (
|
||||
Type,
|
||||
TypeStmt,
|
||||
UnaryExpr,
|
||||
UnionType,
|
||||
VariableExpr,
|
||||
WildcardExpr,
|
||||
)
|
||||
@@ -161,18 +160,7 @@ class MidasParser(Parser):
|
||||
Returns:
|
||||
TypeExpr: the parsed type expression
|
||||
"""
|
||||
return self.union_type()
|
||||
|
||||
def union_type(self) -> Type:
|
||||
types: list[Type] = [self.constraint_type()]
|
||||
while self.match(TokenType.PIPE):
|
||||
types.append(self.constraint_type())
|
||||
if len(types) == 1:
|
||||
return types[0]
|
||||
return UnionType(
|
||||
location=Location.span(types[0].location, types[-1].location),
|
||||
types=types,
|
||||
)
|
||||
return self.constraint_type()
|
||||
|
||||
def constraint_type(self) -> Type:
|
||||
type: Type = self.base_type()
|
||||
|
||||
@@ -4,7 +4,6 @@ import midas.ast.midas as m
|
||||
from midas.checker.types import (
|
||||
AliasType,
|
||||
Type,
|
||||
UnionType,
|
||||
UnknownType,
|
||||
)
|
||||
from midas.resolver.builtin import define_builtins
|
||||
@@ -157,10 +156,6 @@ class MidasResolver(m.Stmt.Visitor[None], m.Expr.Visitor[None], m.Type.Visitor[T
|
||||
# TODO
|
||||
return UnknownType()
|
||||
|
||||
def visit_union_type(self, type: m.UnionType) -> Type:
|
||||
types: list[Type] = [type_.accept(self) for type_ in type.types]
|
||||
return UnionType(alternatives=types)
|
||||
|
||||
def visit_complex_type(self, type: m.ComplexType) -> Type:
|
||||
for prop in type.properties:
|
||||
prop.accept(self)
|
||||
|
||||
@@ -19,7 +19,6 @@ from midas.ast.midas import (
|
||||
Type,
|
||||
TypeStmt,
|
||||
UnaryExpr,
|
||||
UnionType,
|
||||
VariableExpr,
|
||||
WildcardExpr,
|
||||
)
|
||||
@@ -161,12 +160,6 @@ class MidasAstJsonSerializer(
|
||||
"constraint": type.constraint.accept(self),
|
||||
}
|
||||
|
||||
def visit_union_type(self, type: UnionType) -> dict:
|
||||
return {
|
||||
"_type": "UnionType",
|
||||
"types": self._serialize_list(type.types),
|
||||
}
|
||||
|
||||
def visit_complex_type(self, type: ComplexType) -> dict:
|
||||
return {
|
||||
"_type": "ComplexType",
|
||||
|
||||
Reference in New Issue
Block a user