Changeset - d3fc4f54e2ee
[Not reviewed]
default
0 1 0
Laman - 7 years ago 2018-04-15 17:19:29

fixed crash on unknown SGF property
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/sgfParser/property.py
Show inline comments
 
@@ -21,49 +21,49 @@ class Property:
 
	@staticmethod
 
	def create(s,start):
 
		assert Property.fits(s,start)
 
		res=Property()
 
		i,res.name=Property.ident(s,start)
 
		i=skipWhitespace(s,i)
 
		i,x=Property.createValue(s,i,res.name)
 
		res.value=x
 
		i=skipWhitespace(s,i)
 
		return (i,res)
 

	
 
	@staticmethod
 
	def ident(s,start):
 
		m=Property.identRegexp.match(s,start)
 
		if m is None: raise ParserError("expected a property identifier matching '[A-Z]+'",s,start)
 
		return (m.end(),m.group())
 

	
 
	@staticmethod
 
	def createValue(s,start,name):
 
		if name in Property.patterns:
 
			return Property.patterns[name](s,start)
 
		else:
 
			# !! raise or log or ignore
 
			# print('warning, unknown property "{0}" at position {1}'.format(name,start))
 
			return choose(listOf(anything)(s, start), singleton(anything)(s, start))
 
			return choose(listOf(anything), singleton(anything))(s,start)
 

	
 
	@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 GAME_INFO
 
		else: return UNKNOWN
 

	
 
	def copy(self):
 
		res=Property()
 
		res.name=self.name
 
		res.value=self.value if not isinstance(self.value,list) else self.value[:]
 
		return res
 

	
 
	def __str__(self):
 
		val="[{0}]".format(self.value) if not isinstance(self.value,list) else "".join("[{0}]".format(x) for x in self.value)
 
		return "{0}{1}".format(self.name,val)
 

	
 
	patterns={
 
		"B":singleton(move),
 
		"KO":singleton(empty),
 
		"MN":singleton(number),
 
		"W":singleton(move),
 
		"AB":listOf(stone), #
 
		"AE":listOf(point), #
0 comments (0 inline, 0 general)