Skip to content

Commit 108e219

Browse files
committed
Support Hole in match
1 parent f48f6e0 commit 108e219

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

scrapscript.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ class MatchError(Exception):
10751075

10761076

10771077
def match(obj: Object, pattern: Object) -> Optional[Env]:
1078+
if isinstance(pattern, Hole):
1079+
return {} if isinstance(obj, Hole) else None
10781080
if isinstance(pattern, Int):
10791081
return {} if isinstance(obj, Int) and obj.value == pattern.value else None
10801082
if isinstance(pattern, Float):
@@ -2248,6 +2250,12 @@ def test_parse_symbol_returns_symbol(self) -> None:
22482250

22492251

22502252
class MatchTests(unittest.TestCase):
2253+
def test_match_hole_with_non_hole_returns_none(self) -> None:
2254+
self.assertEqual(match(Int(1), pattern=Hole()), None)
2255+
2256+
def test_match_hole_with_hole_returns_empty_dict(self) -> None:
2257+
self.assertEqual(match(Hole(), pattern=Hole()), {})
2258+
22512259
def test_match_with_equal_ints_returns_empty_dict(self) -> None:
22522260
self.assertEqual(match(Int(1), pattern=Int(1)), {})
22532261

0 commit comments

Comments
 (0)