Skip to content

Commit

Permalink
Merge pull request #7 from cdfmlr/simplify_off
Browse files Browse the repository at this point in the history
fix a v0.1.2 bug: simplify works with nested if/func/loop
  • Loading branch information
cdfmlr authored Mar 7, 2021
2 parents 8b4b83f + 94ebab8 commit 4e54d8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions pyflowchart/ast_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(self, ast_func: _ast.FunctionDef, **kwargs): # _ast.For | _ast.Whi
# get nodes
self.func_start = FunctionDefStart(ast_func, **kwargs)
self.func_args_input = FunctionDefArgsInput(ast_func, **kwargs)
self.body_head, self.body_tails = self.parse_func_body()
self.body_head, self.body_tails = self.parse_func_body(**kwargs)
self.func_end = FunctionDefEnd(ast_func, **kwargs)

# connect
Expand All @@ -146,7 +146,7 @@ def __init__(self, ast_func: _ast.FunctionDef, **kwargs): # _ast.For | _ast.Whi

NodesGroup.__init__(self, self.func_start, [self.func_end])

def parse_func_body(self) -> Tuple[Node, List[Node]]:
def parse_func_body(self, **kwargs) -> Tuple[Node, List[Node]]:
"""
parse function body.
Expand All @@ -155,7 +155,7 @@ def parse_func_body(self) -> Tuple[Node, List[Node]]:
- body_head
- body_tails
"""
p = parse(self.ast_object.body)
p = parse(self.ast_object.body, **kwargs)
return p.head, p.tails


Expand Down Expand Up @@ -217,21 +217,21 @@ def __init__(self, ast_loop: _ast.stmt, **kwargs): # _ast.For | _ast.While

NodesGroup.__init__(self, self.cond_node)

self.parse_loop_body()
self.parse_loop_body(**kwargs)

self._virtual_no_tail()

if kwargs.get("simplify", True):
self.simplify()

def parse_loop_body(self) -> None:
def parse_loop_body(self, **kwargs) -> None:
"""
Parse and Connect loop-body (a node graph) to self.cond_node (LoopCondition), extend self.tails with tails got.
"""
progress = parse(self.ast_object.body)
progress = parse(self.ast_object.body, **kwargs)

if progress.head is not None:
process = parse(self.ast_object.body)
process = parse(self.ast_object.body, **kwargs)
# head
self.cond_node.connect_yes(process.head)
# tails connect back to cond
Expand Down Expand Up @@ -357,17 +357,17 @@ def __init__(self, ast_if: _ast.If, **kwargs):

NodesGroup.__init__(self, self.cond_node)

self.parse_if_body()
self.parse_else_body()
self.parse_if_body(**kwargs)
self.parse_else_body(**kwargs)

if kwargs.get("simplify", True):
self.simplify()

def parse_if_body(self) -> None:
def parse_if_body(self, **kwargs) -> None:
"""
Parse and Connect if-body (a node graph) to self.cond_node (IfCondition).
"""
progress = parse(self.ast_object.body)
progress = parse(self.ast_object.body, **kwargs)

if progress.head is not None:
self.cond_node.connect_yes(progress.head)
Expand All @@ -382,11 +382,11 @@ def parse_if_body(self) -> None:

self.append_tails(virtual_yes)

def parse_else_body(self) -> None:
def parse_else_body(self, **kwargs) -> None:
"""
Parse and Connect else-body (a node graph) to self.cond_node (IfCondition).
"""
progress = parse(self.ast_object.orelse)
progress = parse(self.ast_object.orelse, **kwargs)

if progress.head is not None:
self.cond_node.connect_no(progress.head)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyflowchart',
version='0.1.2',
version='0.1.3',
url='https://github.com/cdfmlr/pyflowchart',
license='MIT',
author='CDFMLR',
Expand Down

0 comments on commit 4e54d8e

Please sign in to comment.