Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/celpy/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,12 @@ def expr(self, tree: lark.Tree) -> Result:
elif len(tree.children) == 3:
# full conditionalor "?" conditionalor ":" expr.
func = self.functions["_?_:_"]
cond_value, left, right = cast(Tuple[Result, Result, Result], self.visit_children(tree))
cond_value = self.visit(tree.children[0])
try:
return func(cond_value, left, right)
return self.visit(tree.children[1]) if func(cond_value, True, False) else self.visit(tree.children[2])
except TypeError as ex:
left = self.visit(tree.children[1]) if cond_value else '-'
right = self.visit(tree.children[2]) if cond_value else '-'
self.logger.debug("%s(%s, %s) --> %s", func.__name__, left, right, ex)
err = (
f"found no matching overload for _?_:_ "
Expand All @@ -1341,6 +1343,9 @@ def expr(self, tree: lark.Tree) -> Result:
column=tree.meta.column,
)

def visit(self, child: Union[str, lark.Tree]):
return super().visit(child) if isinstance(child, lark.Tree) else child

@trace
def conditionalor(self, tree: lark.Tree) -> Result:
"""
Expand Down
1 change: 1 addition & 0 deletions type_check/lineprecision.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ celpy.celtypes 1495 430 17 221 788 39
celpy.evaluation 2434 824 33 172 1390 15
xlate 0 0 0 0 0 0
xlate.c7n_to_cel 1730 384 105 145 1091 5