def parseGameTree()

in pachi_py/pachi/tools/sgflib/sgflib.py [0:0]


	def parseGameTree(self):
		""" Called when "(" encountered, ends when a matching ")" encountered.
			Parses and returns one 'GameTree' from 'self.data'. Raises
			'GameTreeParseError' if a problem is encountered."""
		g = GameTree()
		while self.index < self.datalen:
			match = self.reGameTreeNext.match(self.data, self.index)
			if match:
				self.index = match.end()
				if match.group(1) == ";":				# found start of node
					if g.variations:
						raise GameTreeParseError(
									"A node was encountered after a variation.")
					g.append(g.makeNode(self.parseNode()))
				elif match.group(1) == "(":				# found start of variation
					g.variations = self.parseVariations()
				else:									# found end of GameTree ")"
					return g
			else:										# error
				raise GameTreeParseError
		return g