block.py
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Block:
def __init__(self, type, line=''):
self.blocks = list()
self.code = line
self.blockType = type
self.indent = -1
def setIndent(self, indent):
self.indent = indent
def addLine(self, line):
if len(self.code) > 0:
self.code += '\n'
self.code += line
def addBlock(self, block):
self.blocks.append(block)
def debug(self):
if self.blockType != 'TYPE_NORMAL':
print("Block Info:", self.blockType, self.indent)
print(self.code)
for block in self.blocks:
if block.indent <= self.indent:
raise ValueError("Invalid Indent Error Occurred: {}, INDENT {} included in {}, INDENT {}".format(block.code, block.indent, self.code, self.indent))
block.debug()
def __str__(self):
if len(self.code) > 0:
result = self.code + '\n'
else:
result = ''
for block in self.blocks:
result += block.__str__()
return result