Create note package

This commit is contained in:
Bartłomiej Pluta
2019-07-03 10:16:05 +02:00
parent f826516d8f
commit 2823fd1896
40 changed files with 188 additions and 958 deletions

View File

0
smnp/ast/node/access.py Normal file
View File

View File

View File

0
smnp/ast/node/block.py Normal file
View File

0
smnp/ast/node/colon.py Normal file
View File

View File

View File

0
smnp/ast/node/integer.py Normal file
View File

0
smnp/ast/node/list.py Normal file
View File

41
smnp/ast/node/model.py Normal file
View File

@@ -0,0 +1,41 @@
from smnp.note.model import Note
class Node:
def __init__(self, parent, pos):
self.children = []
self.parent = parent
self.pos = pos
for child in self.children:
child.parent = self
def __repr__(self):
return self.__str__()
def __len__(self):
return len(self.children)
def __getitem__(self, index):
return self.children[index]
def append(self, node):
node.parent = self
self.children.append(node)
def pop(self, index):
return self.children.pop(index)
def _print(self, level):
string = f"{pad(level)}{self.__class__.__name__}({self.parent.__class__.__name__}):\n"
for child in self.children:
if isinstance(child, str) or isinstance(child, int) or isinstance(child, Note):
string += pad(level + 1) + f"'{child}'\n"
else:
string += child._print(level + 1)
return string
def __str__(self):
return self._print(0)
def pad(level):
return (" " * level)

0
smnp/ast/node/note.py Normal file
View File

0
smnp/ast/node/percent.py Normal file
View File

0
smnp/ast/node/program.py Normal file
View File

0
smnp/ast/node/ret.py Normal file
View File

0
smnp/ast/node/string.py Normal file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

0
smnp/ast/parsers/list.py Normal file
View File

View File

0
smnp/ast/parsers/note.py Normal file
View File

0
smnp/ast/parsers/ret.py Normal file
View File

View File

View File

View File