Changeset - 36762e70d969
[Not reviewed]
default
0 2 0
Laman - 9 years ago 2016-10-13 22:43:53

work on proper parsing
2 files changed with 47 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/diana/sgf.py
Show inline comments
 
@@ -3,4 +3,10 @@
 
		self.collection=collection
 
 
	def getGameRecords(self):
 
		pass
 
\ No newline at end of file
 
		pass
 
 
class Game:
 
	pass
 
 
class Node:
 
	pass
src/diana/sgfParser.py
Show inline comments
 
@@ -15,6 +15,10 @@ class Collection:
 
		while x is not None:
 
			self.gameTrees.append(x)
 
			i,x=GameTree.create(s,i)
 
 
	def listGames(self):
 
		for tree in self.gameTrees:
 
			for game in tree.listGames(): yield game
 
	
 
class GameTree:
 
	def __init__(self):
 
@@ -46,6 +50,29 @@ class GameTree:
 
			# print("error when parsing GameTree")
 
			return (i,None)
 
		return (i+1,res)
 
 
	## Expand multiple games into distinct GameTrees and yield each.
 
	def listGames(self):
 
		for node in self._listGINodes():
 
			yield self._buildSubtree(node)
 
 
	## Create and return a new GameTree containing the provided Node.
 
	#
 
	# The Node objects are shared between the trees, not copied.
 
	def _buildSubtree(self,node):
 
		res=GameTree()
 
 
		return res
 
		# chci celou cestu ke kořeni a všechny podstromy nodu
 
 
	## Find and yield Game Info nodes.
 
	def _listGINodes(self):
 
		for node in self.nodes:
 
			if node.isGINode():
 
				yield node
 
		for tree in self.branches:
 
			for node in tree._listGINodes():
 
				yield node
 
	
 
class Node:
 
	def __init__(self):
 
@@ -68,7 +95,10 @@ class Node:
 
			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
 
@@ -78,6 +108,9 @@ class Node:
 
		else: return None
 
	
 
class Property:
 
	GAME_INFO=1
 
	UNKNOWN=99
 
 
	def __init__(self):
 
		self.name=""
 
		self.value=""
 
@@ -102,6 +135,12 @@ class Property:
 
		if m is None: return (start,None)
 
		return (m.end(),m.group())
 
 
	@property
 
	def type(self):
 
		gameInfo=["AN","BR","BT","CP","DT","EV","GN","GC","ON","OT","PB","PC","PW","RE","RO","RU","SO","TM","US","WR","WT"]
 
		if self.name in gameInfo: return Property.GAME_INFO
 
		else: return Property.UNKNOWN
 
 
class PropValue:
 
	def __init__(self):
 
		self.type=""
0 comments (0 inline, 0 general)