diff --git a/src/diana/sgfParser.py b/src/diana/sgfParser.py --- a/src/diana/sgfParser.py +++ b/src/diana/sgfParser.py @@ -20,24 +20,6 @@ class GameTree: def __init__(self): self.nodes=[] self.branches=[] - - # def __init__(self,s,start): - # self.nodes=[] - # self.branches=[] - # if s[start]!="(": - # print("error when parsing GameTree") - # return (-1,None) - # i,x=Node(s,start+1) - # if x is None: - # print("error when parsing GameTree") - # return (-1,None) - # while x is not None: - # self.nodes.append(x) - # i,x=Node(s,i) - # if s[i]!=")": - # print("error when parsing GameTree") - # return (-1,None) - # return (i+1,self) @staticmethod def create(s,start): @@ -111,10 +93,6 @@ class Property: if x is None: print('error when parsing property "{0}" at position {1}'.format(res.name,i)) return (start,None) - # while x is not None: # přesunuto do PropValue.listOf - # res.values.append(x) - # i=skipWhitespace(s,i) - # i,x=PropValue.create(s,i,res.name) return (i,res) @staticmethod @@ -138,15 +116,6 @@ class PropValue: else: print('warning, unknown property "{0}" at position {1}'.format(name,start)) return PropValue.singleton(PropValue.anything)(s,start) - - # def singleton(s,start,vType): - # if s[start]!="[": - # return (start,None) - # i,x=vType(s,start+1) - # if x is None: return (start,None) - # if s[i]!="]": - # return (start,None) - # return (i+1,x) def choose(*vTypes): def f(s,start): @@ -166,16 +135,6 @@ class PropValue: return (start,None) return (i+1,x) return f - - # def listOf(s,start,vType,allowEmpty=False): - # res=[] - # i,x=singleton(s,start,vType) - # # singleton(vType) if vType not tuple else compose(vType[0],vType[1]) - # while x!=None: - # res.append(x) - # i,x=singleton(s,i,vType) - # if len(res)==0 and not allowEmpty: return (start,None) - # return (i,res) def listOf(vType,allowEmpty=False): def f(s,start): @@ -188,13 +147,6 @@ class PropValue: if len(res)==0 and not allowEmpty: return (start,None) return (i,res) return f - - # def compose(s,start,vTypeA,vTypeB): - # i,a=vTypeA(s,start) - # if a==None or s[i]!=":": return (start,None) - # i,b=vTypeB(s,i+1) - # if b==None: return start,None - # return (i,(a,b)) def compose(vTypeA,vTypeB): def f(s,start): @@ -233,22 +185,6 @@ class PropValue: m=r.match(s,start) if m is None: return (start,None) return (m.end(),m.group(0)) - - # def simpleText(s,start): - # res="" - # esc=False - # lineBreak=False - # for c in s: - # if esc: - # res+=c - # esc=False - # elif c=="\\": - # esc=True - # elif c=="]": - # break - # else: - # res+=c - # return res def text(simple=True,composed=False): def f(s,start): @@ -378,75 +314,6 @@ class ParserError(Exception): self.col=col self.message=message - - -"""def property(s): - # i=propIdent(s) - # if i<0: return -1 - # j=i - # i=propValue(s[i:]) - # while i>=0: - # j+=i - # i=propValue(s[i:]) - # return j - -def propIdent(s): - m=re.match(r"[A-Z]+",s) - if m is None: return -1 - return m.end() - -def propValue(s): - i=cValueType(s[1:]) - if s[0]=="[" and i>=0 and s[i]=="]": return i+1 - else: return -1 - -class propValue: - pass - -def cValueType(s,start): - matches=[real,number,double,color,simpleText] - for f in matches: - i,x=f(s,start) - if x is not None: return i,x - return 1/0 - -def number(s,start): - r=re.compile(r"(\+|-|)\d+") - m=r.match(s,start) - if m is None: return (-1,None) - x=int(m.group(0)) - return (m.end(),x) - -def real(s): - m=re.match(r"(\+|-|)\d+(\.\d+)?",s) - if m is None: return -1 - return m.end() - -def double(s): - m=re.match(r"1|2",s) - if m is None: return -1 - return m.end() - -def color(s): - m=re.match(r"B|W",s) - if m is None: return -1 - return m.end() - -def simpleText(s): - res=r"" - esc=False - for c in s: - if esc: - res+=c - esc=False - elif c=="\\": - esc=True - elif c=="]": - break - else: - res+=c - return res""" - # TODO: # date