diff --git a/gen/midas.py b/gen/midas.py index dc0efd0..e1c304d 100644 --- a/gen/midas.py +++ b/gen/midas.py @@ -111,10 +111,6 @@ class ConstraintType: constraint: Expr -class UnionType: - types: list[Type] - - class ComplexType: properties: list[PropertyStmt] diff --git a/midas/ast/midas.py b/midas/ast/midas.py index a18b460..335e5cf 100644 --- a/midas/ast/midas.py +++ b/midas/ast/midas.py @@ -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] diff --git a/midas/ast/printer.py b/midas/ast/printer.py index ee59279..41dd6a0 100644 --- a/midas/ast/printer.py +++ b/midas/ast/printer.py @@ -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 diff --git a/midas/checker/types.py b/midas/checker/types.py index d9d91b7..d62c867 100644 --- a/midas/checker/types.py +++ b/midas/checker/types.py @@ -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 diff --git a/midas/cli/highlighter.py b/midas/cli/highlighter.py index 690c408..b1b705f 100644 --- a/midas/cli/highlighter.py +++ b/midas/cli/highlighter.py @@ -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: diff --git a/midas/cli/hl_midas.css b/midas/cli/hl_midas.css index f5b3d1d..fabb84e 100644 --- a/midas/cli/hl_midas.css +++ b/midas/cli/hl_midas.css @@ -8,7 +8,6 @@ span { &.named-type, &.generic-type, &.constraint-type, - &.union-type, &.complex-type { --col: 150, 150, 150; } diff --git a/midas/lexer/midas.py b/midas/lexer/midas.py index eec44d5..124ea09 100644 --- a/midas/lexer/midas.py +++ b/midas/lexer/midas.py @@ -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 diff --git a/midas/lexer/token.py b/midas/lexer/token.py index 9b30940..f08964a 100644 --- a/midas/lexer/token.py +++ b/midas/lexer/token.py @@ -23,7 +23,6 @@ class TokenType(Enum): AND = auto() QMARK = auto() DOT = auto() - PIPE = auto() # Operators # PLUS = auto() diff --git a/midas/parser/midas.py b/midas/parser/midas.py index 9af46da..5d09b83 100644 --- a/midas/parser/midas.py +++ b/midas/parser/midas.py @@ -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() diff --git a/midas/resolver/midas.py b/midas/resolver/midas.py index 9ffce85..acbbe96 100644 --- a/midas/resolver/midas.py +++ b/midas/resolver/midas.py @@ -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) diff --git a/tests/serializer/midas.py b/tests/serializer/midas.py index 6da0dec..919dc66 100644 --- a/tests/serializer/midas.py +++ b/tests/serializer/midas.py @@ -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",