Skip to content

Commit

Permalink
Oversight in Top/Bottom parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbgn committed Jul 15, 2023
1 parent a23d3ed commit 6d8ff15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/test_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
11 changes: 9 additions & 2 deletions transforge/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6d8ff15

Please sign in to comment.