Skip to content

Commit ad2c897

Browse files
committed
wip
1 parent 3861557 commit ad2c897

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

scrapscript.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ def parse_assign(tokens: typing.List[Token], p: float = 0) -> "Assign":
367367
return assign
368368

369369

370+
def build_match_case(expr: "Object") -> "MatchCase":
371+
if not isinstance(expr, Function):
372+
raise ParseError(f"expected function in match expression {expr!r}")
373+
arg, body = expr.arg, expr.body
374+
return MatchCase(arg, body)
375+
376+
370377
def parse(tokens: typing.List[Token], p: float = 0) -> "Object":
371378
if not tokens:
372379
raise UnexpectedEOFError("unexpected end of input")
@@ -404,15 +411,11 @@ def parse(tokens: typing.List[Token], p: float = 0) -> "Object":
404411
l = Spread()
405412
elif token == Operator("|"):
406413
expr = parse(tokens, PS["|"].pr) # TODO: make this work for larger arities
407-
if not isinstance(expr, Function):
408-
raise ParseError(f"expected function in match expression {expr!r}")
409-
cases = [MatchCase(expr.arg, expr.body)]
414+
cases = [build_match_case(expr)]
410415
while tokens and tokens[0] == Operator("|"):
411416
tokens.pop(0)
412417
expr = parse(tokens, PS["|"].pr) # TODO: make this work for larger arities
413-
if not isinstance(expr, Function):
414-
raise ParseError(f"expected function in match expression {expr!r}")
415-
cases.append(MatchCase(expr.arg, expr.body))
418+
cases.append(build_match_case(expr))
416419
l = MatchFunction(cases)
417420
elif isinstance(token, LeftParen):
418421
if isinstance(tokens[0], RightParen):

0 commit comments

Comments
 (0)