Changeset - 36b0271e7393
[Not reviewed]
default
0 2 0
Laman - 6 years ago 2019-05-29 16:30:43

more lenient and robust error handling
2 files changed with 9 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/diana/sgfParser/node.py
Show inline comments
 
from collections import deque
 
import logging as log
 

	
 
from . import skipWhitespace, ParserWarning
 
from .property import Property, GAME_INFO
 
@@ -23,8 +24,7 @@ class Node:
 
		while Property.fits(s,i):
 
			i,x=Property.create(s,i)
 
			if x.name in res.properties:
 
				# !! raise or log or ignore
 
				raise ParserWarning('duplicate "{0}" property in a node. second value ignored'.format(x.name),s,i)
 
				log.warning(ParserWarning('duplicate "{0}" property in a node. second value ignored'.format(x.name),s,i))
 
			else:
 
				res.properties[x.name]=x
 
			i=skipWhitespace(s,i)
src/diana/sgfParser/property.py
Show inline comments
 
import re
 
import logging as log
 

	
 
from .propValues import choose, singleton, listOf, compose, number, real, double, color, text, empty, anything, point, move, stone
 
from . import skipWhitespace, ParserError
 
@@ -24,7 +25,12 @@ class Property:
 
		res=Property()
 
		i,res.name=Property.ident(s,start)
 
		i=skipWhitespace(s,i)
 
		i,x=Property.createValue(s,i,res.name)
 
		try:
 
			i,x=Property.createValue(s,i,res.name)
 
		except ParserError as e: # malformed value
 
			log.warning(e)
 
			i,x=choose(listOf(anything), singleton(anything))(s,i)
 
			res.name="_"+res.name
 
		res.value=x
 
		i=skipWhitespace(s,i)
 
		return (i,res)
0 comments (0 inline, 0 general)