Skip to content

Commit 7dacfff

Browse files
committed
Add append method to BLOCK
Refactorize code to re-utilize append method.
1 parent e8808c4 commit 7dacfff

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/symbols/block.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@ def __init__(self, *nodes):
2424
def make_node(cls, *args):
2525
""" Creates a chain of code blocks.
2626
"""
27-
new_args = []
28-
29-
args = [x for x in args if not is_null(x)]
30-
for x in args:
31-
assert isinstance(x, Symbol)
32-
if x.token == 'BLOCK':
33-
new_args.extend(SymbolBLOCK.make_node(*x.children).children)
34-
else:
35-
new_args.append(x)
36-
37-
result = SymbolBLOCK(*new_args)
27+
result = SymbolBLOCK()
28+
result.append(*args)
3829
return result
3930

4031
def __getitem__(self, item):
@@ -54,3 +45,13 @@ def __hash__(self):
5445

5546
def pop(self, pos: int) -> Symbol:
5647
return self.children.pop(pos)
48+
49+
def append(self, *args):
50+
for arg in args:
51+
if check.is_null(arg):
52+
continue
53+
assert isinstance(arg, Symbol), f"Invalid argument '{arg}'"
54+
if arg.token == 'BLOCK':
55+
self.append(*arg.children)
56+
else:
57+
self.children.append(arg)

0 commit comments

Comments
 (0)