diff --git a/tests/test_lang.py b/tests/test_lang.py index 3677d6d..1034e10 100644 --- a/tests/test_lang.py +++ b/tests/test_lang.py @@ -194,9 +194,11 @@ def test_parse_type_uri(self): lang = Language(scope=locals(), namespace=EX, canon={F(F(A, A), A)}) t = F(F(A, A), A) s = F(A, F(A, A)) + u = F(A, F(Top, A)) self.assertEqual(lang.uri(t), EX["F-F-A-A-A"]) self.assertEqual(lang.parse_type_uri(EX["F-F-A-A-A"]), t) self.assertEqual(lang.parse_type_uri(EX["F-A-F-A-A"]), s) + self.assertEqual(lang.parse_type_uri(EX["F-A-F-Top-A"]), u) if __name__ == '__main__': diff --git a/transforge/lang.py b/transforge/lang.py index 934f3e5..e8aebce 100644 --- a/transforge/lang.py +++ b/transforge/lang.py @@ -11,7 +11,7 @@ from rdflib.namespace import ClosedNamespace from collections import defaultdict -from transforge.namespace import TF, EX +from transforge.namespace import TF, EX, shorten from transforge.type import (builtins, Product, TypeOperator, TypeInstance, TypeVariable, TypeOperation, TypeAlias, Direction, Type, TypeSchema, TypingError, Top, Bottom) @@ -340,7 +340,14 @@ def parse_operator(self, token: str) -> Operator: def parse_type_uri(self, uri: URIRef) -> TypeInstance: """Parse an URI back to a concrete type instance. Inverse operation to `.uri()`.""" - ops = [self.types[x] for x in uri[len(self.namespace):].split("-")] + ops = [] + for x in shorten(uri).split("-"): + if x == "Top": + ops.append(Top) + elif x == "Bottom": + ops.append(Bottom) + else: + ops.append(self.types[x]) types: list[TypeInstance] = [] while ops: op = ops.pop()