Skip to content

Commit

Permalink
Add case
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Aug 14, 2023
1 parent be77ca2 commit 2ea6f88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion auto_editor/formats/final_cut_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ea6f88

Please sign in to comment.