From 2ea6f88e342f2d77f60e204d57f87c72e1f1bbfa Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Mon, 14 Aug 2023 01:51:13 -0400 Subject: [PATCH] Add case --- auto_editor/formats/final_cut_pro.py | 1 - auto_editor/lang/palet.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/auto_editor/formats/final_cut_pro.py b/auto_editor/formats/final_cut_pro.py index c0a450d89..b5a4ebf12 100644 --- a/auto_editor/formats/final_cut_pro.py +++ b/auto_editor/formats/final_cut_pro.py @@ -41,7 +41,6 @@ def get_colorspace(src: FileInfo) -> str: def fcp_xml(group_name: str, output: str, tl: v3) -> None: - def fraction(val: int) -> str: if val == 0: return "0s" diff --git a/auto_editor/lang/palet.py b/auto_editor/lang/palet.py index dde75397d..bbb6947fe 100644 --- a/auto_editor/lang/palet.py +++ b/auto_editor/lang/palet.py @@ -1099,6 +1099,22 @@ def syn_cond(env: Env, node: list) -> Any: return None +def syn_case(env: Env, node: list) -> Any: + val_expr = my_eval(env, node[1]) + for case_clause in node[2:]: + if not (type(case_clause) == list and len(case_clause) == 2): + raise MyError("case: bad syntax") + if type(case_clause[0]) == list: + for case in case_clause[0]: + if is_equal(my_eval(env, case), val_expr): + return my_eval(env, case_clause[1]) + elif type(case_clause[0]) == Sym and case_clause[0].val == "else": + return my_eval(env, case_clause[1]) + else: + raise MyError("case: bad syntax") + return None + + def syn_let(env: Env, node: list) -> Any: if len(node) < 2: raise MyError(f"{node[0]}: Arity mismatch: Expected at least 1 term") @@ -1263,6 +1279,7 @@ def my_eval(env: Env, node: object) -> Any: "if": Syntax(syn_if), "when": Syntax(syn_when), "cond": Syntax(syn_cond), + "case": Syntax(syn_case), "let": Syntax(syn_let), "let*": Syntax(syn_let_star), # loops