Skip to content

Commit

Permalink
Added support for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan26roy committed Jan 7, 2024
1 parent db9b24a commit 22b8ffb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/formulate/AST.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ def to_python(self):
return "np.exp(1)"
case "e":
return "np.exp(1)"
case "max":
return f"root_max({self.arguments[0]})"
case "min":
return f"root_min({self.arguments[0]})"
case "sum":
return f"root_sum({self.arguments[0]})"
case "no_of_entries":
return f"root_length({self.arguments[0]})"
case "min_if":
return f"root_min_if({self.arguments[0]}, {self.arguments[1]})"
case "max_if":
return f"root_max_if({self.arguments[0]}, {self.arguments[1]})"
case _ :
raise ValueError("Not a valid function!")

Expand Down
2 changes: 1 addition & 1 deletion src/formulate/ttreeformula.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
func_name: CNAME | CNAME "::" func_name
trailer: "(" [arglist] ")"
arglist: expression ("," expression)* [","]
CNAME: /[A-Za-z_]([A-Za-z0-9_]|\s*\.\s*)*/
CNAME: /[A-Za-z_$]([A-Za-z0-9_$]|\s*\.\s*)*/
%import common.NUMBER
%import common.WS
Expand Down

0 comments on commit 22b8ffb

Please sign in to comment.