from . import skipWhitespace, ParserError from .property import Property class Node: def __init__(self): self.properties=dict() self._parent=None self._children=[] @staticmethod def create(s,start): res=Node() if s[start]!=";": # print("error when parsing Node") return (start,None) i=skipWhitespace(s,start+1) i,x=Property.create(s,start+1) while x is not None: if x.name in res.properties: print(res.properties) raise ParserError(0,0,'duplicate "{0}" property in node at position {1}. second value ignored'.format(x.name,start)) else: res.properties[x.name]=x i=skipWhitespace(s,i) i,x=Property.create(s,i) return (i,res) def isGINode(self): return any(prop.type==Property.GAME_INFO for prop in self.properties.values()) def setProperty(self,name,value): self.properties[name]=value # zkontrolovat typ value def setParent(self,node): self._parent=node def addChild(self,node): if node in self._children: return node self._children.append(node) return node def removeChild(self,node): if node not in self._children: return None del self._children[self._children.index(node)] return node def removeChildAt(self,i): if -len(self._children)