diff --git a/src/sgfParser/collection.py b/src/sgfParser/collection.py --- a/src/sgfParser/collection.py +++ b/src/sgfParser/collection.py @@ -1,93 +1,93 @@ -from sgfParser.node import Node -from . import skipWhitespace, ParserError - - -class Collection: - def __init__(self,s): - self.gameTrees=[] - i=skipWhitespace(s,0) - if i>=len(s): return - elif not GameTree.fits(s,i): - raise ParserError("expected a GameTree starting with '('",s,i) - while GameTree.fits(s,i): - i,x=GameTree.create(s,i) - self.gameTrees.append(x) - if i=len(s) or s[i]!=")": - raise ParserError("expected end of a GameTree marked by ')'",s,i) - i=skipWhitespace(s,i+1) - return (i,res) - - ## Expand multiple games into distinct GameTrees and yield each. - def listGames(self): - for node in self._listGINodes(): - yield self._buildSubtree(node) - - def getNode(self,i): - if 0<=i=len(s): return + elif not GameTree.fits(s,i): + raise ParserError("expected a GameTree starting with '('",s,i) + while GameTree.fits(s,i): + i,x=GameTree.create(s,i) + self.gameTrees.append(x) + if i=len(s) or s[i]!=")": + raise ParserError("expected end of a GameTree marked by ')'",s,i) + i=skipWhitespace(s,i+1) + return (i,res) + + ## Expand multiple games into distinct GameTrees and yield each. + def listGames(self): + for node in self._listGINodes(): + yield self._buildSubtree(node) + + def getNode(self,i): + if 0<=i