Skip to content

Commit

Permalink
Removed all lark import statements
Browse files Browse the repository at this point in the history
Signed-off-by: Aryan Roy <[email protected]>
  • Loading branch information
aryan26roy committed Sep 14, 2024
1 parent 2f34a9b commit 9f6df99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
31 changes: 20 additions & 11 deletions src/formulate/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"""
from __future__ import annotations

import lark
from . import numexpr_parse
from . import ttreeformula_parser

UNARY_OP = {"pos", "neg", "binv", "linv"}
with_sign = {}
Expand Down Expand Up @@ -34,16 +35,15 @@
}


def _ptree_to_string(exp_tree: lark.tree.Tree, out_exp: list):
# print("==================================")
# print(exp_tree)
# print("==================================")
if isinstance(exp_tree, lark.lexer.Token):
def _ptree_to_string(exp_tree, out_exp: list):
if isinstance(exp_tree, numexpr_parser.Token) or isinstance(exp_tree, ttreeformula_parser.Token):
out_exp.append(str(exp_tree))
return out_exp

elif exp_tree is None:
return out_exp
elif isinstance(exp_tree.data, lark.lexer.Token):

elif isinstance(exp_tree.data, numexpr_parser.Token) or isinstance(exp_tree.data, ttreeformula_parser.Token):
cur_type = exp_tree.data.type
cur_val = exp_tree.data.value
children = exp_tree.children
Expand All @@ -64,9 +64,9 @@ def _ptree_to_string(exp_tree: lark.tree.Tree, out_exp: list):
out_exp.append(val_to_sign[cur_val])
out_exp.extend(_ptree_to_string(children[1], []))
out_exp.append(")")

else:
children = exp_tree.children
print(exp_tree.data)
# print(exp_tree, "adwe")
if exp_tree.data in UNARY_OP:
child = exp_tree.children[0]
Expand All @@ -75,45 +75,54 @@ def _ptree_to_string(exp_tree: lark.tree.Tree, out_exp: list):
out_exp.extend(_ptree_to_string(child, []))
out_exp.append(")")
return out_exp

if len(children) == 1 and (
children[0].type == "CNAME" or children[0].type == "NUMBER"
):
# print(str(children[0]))
out_exp.append(str(children[0]))
return out_exp

if exp_tree.data == "func":
children = exp_tree.children
head = children[0]
tail = children[1]
pre_name = head.children[0]
out_exp.append(str(pre_name))

if len(head.children) > 1:
subchild = head.children[1]
while not isinstance(subchild, lark.lexer.Token):

while not (isinstance(subchild, numexpr_parser.Token) or isinstance(subchild, ttreeformula_parser.Token)):
out_exp.append("::")
out_exp.append(str(subchild.children[0]))

if len(subchild.children) > 1:
subchild = subchild.children[1]
else:
break
print(out_exp)

print(out_exp, "gfege")
out_exp.append("(")
out_exp.extend(_ptree_to_string(tail, []))
out_exp.append(")")
return out_exp

if exp_tree.data != "matr":
out_exp.append("(")
out_exp.extend(_ptree_to_string(children[0], []))

for i in range(1, len(children)):

if exp_tree.data == "matr":
out_exp.append("[")

else:
out_exp.append(val_to_sign[exp_tree.data])
out_exp.extend(_ptree_to_string(children[i], []))

if exp_tree.data == "matr":
out_exp.append("]")

if exp_tree.data != "matr":
out_exp.append(")")
return out_exp
1 change: 0 additions & 1 deletion src/formulate/matching_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""


import lark
from . import numexpr_parser
from . import ttreeformula_parser

Expand Down

0 comments on commit 9f6df99

Please sign in to comment.