Skip to content

Commit

Permalink
Merge pull request #9 from tommyyliu/master
Browse files Browse the repository at this point in the history
Fix case where there's a newline separating prop identifier and value.
  • Loading branch information
sanderland authored Jan 23, 2025
2 parents 3cf9be1 + 4d1149f commit a3e12e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pysgf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def __init__(self, contents):

def _parse_branch(self, current_move: SGFNode):
while self.ix < len(self.contents): # https://xkcd.com/1171/
match = re.match(r"\s*(?:\(|\)|;|(?:(\w+)((?:\[.*?(?<!\\)\]\s*)+)))", self.contents[self.ix :], re.DOTALL)
match = re.match(r"\s*(?:\(|\)|;|(?:(\w+)\s*((?:\[.*?(?<!\\)\]\s*)+)))", self.contents[self.ix :], re.DOTALL)
if not match:
break
self.ix += len(match[0])
Expand Down
24 changes: 24 additions & 0 deletions tests/data/kgs.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(;GM[1]
FF[4]
SZ[19]
PW[stakeout]
WR[9d]
PB[azlan]
BR[1d]
DT[2018-06-26]
PC[The KGS Go Server at http://www.gokgs.com/]
KM[0.50]
RE[W+Resign]
RU[Japanese]
OT[3x20 byo-yomi]
CA[UTF-8]
ST[2]
AP[CGoban:3]
TM[0]
HA[2]
AB[pd]
[dp]

;W[pp];B[nq];W[dd];B[pn];W[on];B[po];W[oo];B[op];W[pq];B[om];W[mo];B[mp];W[pm];B[qm];W[pl];B[ql];W[ro];B[pk];W[ol];B[ok];W[nl];B[qn];W[lo];B[lp];W[ko];B[kp];W[jp];B[jq];W[iq];B[ip];W[jo];B[ir];W[hq];B[hr];W[gq];B[gr];W[fq];B[fr];W[eq];B[dq];W[er];B[dr];W[nk];B[pg];W[pi];B[oi];W[oh];B[ph];W[oj];B[qi];W[pj];B[qk];W[qj];B[rj];W[ni];B[rh];W[dm];B[dk];W[es];B[em];W[en];B[dn];W[el];B[cm];W[fm];B[cn];W[pc];B[oc];W[ob];B[qc];W[pb];B[nc];W[qd];B[qe];W[rd];B[re];W[rc];B[fc];W[fj];B[mj];W[nj];B[jj];W[jh];B[hi];W[gd];B[fi];W[fd];B[dc];W[cc];B[ed];W[ee];B[ec];W[gc];B[cd];W[de];B[cb];W[bc];B[bb];W[bd];B[gb];W[hb];B[fa];W[ej];B[gj];W[gh];B[gi];W[ig];B[ei];W[dj];B[di];W[cj];B[ki];W[lg];B[hl];W[jl];B[jk];W[il];B[hk];W[ci];B[gg];W[hh];B[ch];W[eg];B[fh];W[fg];B[dg];W[cf];B[bh];W[gn];B[bf];W[be];B[cg];W[ii];B[ij];W[af];B[ag];W[bg];B[fk];W[ek];B[bf];W[ab];B[ae];W[ha];B[eb];W[da];B[kc];W[od];B[pe];W[mc];B[nd];W[md];B[ne];W[nb];B[me];W[le];B[ld];W[lc];B[lf];W[ke];B[kf];W[je];B[jf];W[if];B[mg];W[oq];B[np];W[nr];B[mr];W[or];B[kr];W[rn];B[kl];W[km];B[ll];W[lm];B[hm];W[cl];B[hn];W[ho];B[fl];W[bm];B[bn];W[bl];B[br];W[an];B[ao];W[am];B[bp];W[rm];B[rl];W[sl];B[sk];W[sm];B[qo];W[qp];B[rk];W[ml];B[lj];W[in];B[im];W[jm];B[kg];W[ie];B[kh];W[ng];B[mh];W[nf];B[oe];W[bi];B[ai];W[aj];B[ah];W[df];B[gm];W[fo];B[ep];W[eo];B[rp];W[rq];B[no];W[nn];B[sp];W[sq];B[kb];W[kd];B[hc];W[ic];B[hd];W[he];B[fe];W[ge];B[ff];W[gf];B[ca];W[ga];B[ac];W[ad];B[aa];W[ba];B[lb];W[mb];B[aa];W[fb];B[ac];W[af];B[ea];W[db];B[ae];W[lk];B[kk];W[af];B[ji];W[ih];B[ae];W[qh];B[qg];W[af];B[nh];W[bg];B[dh];W[og];B[bf];W[do];B[co];W[ds];B[cs];W[fs];B[fp];W[gp];B[ae];W[gs];B[af];W[is];B[jr];W[hs];B[ns];W[lq];B[ms];W[js];B[ks];W[lr];B[qr];W[mq];B[jn];W[kn];B[mk];W[mi];B[li];W[mf];B[lh];W[of];B[pf];W[oi];B[qq];W[kq];B[rr];W[so];B[rp];W[sa];B[sr];W[sp];B[ps];W[ss];B[rs];W[pr];B[os];W[as];B[nq];W[np];B[mm];W[nm];B[ak];W[bj];B[bk];W[ck];B[ec];W[dc];B[ib];W[id];B[eh];W[ef];B[rb];W[qb];B[sc];W[sd];B[se];W[sb];B[ra];W[qa];B[io];W[jn];B[ik];W[jg];B[bs];W[];B[cq];W[];B[ea];W[];B[ed];W[];B[fe];W[];B[eb];W[];B[hc];W[];B[ia];W[];B[fa];W[gb];B[];TW[ra][rb][qc][sc][ld][mm][om][ln][mn][sn][no][kp][lp][mp][op][rp][nq]TB
[od][qf][rf][sf][bg][lg][rg][sg][qh][sh][ri][si][hj][kj][sj][gk][lk][gl]
[bo][cp][cr]W[])
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ def test_pandanet():
def test_ogs():
file = os.path.join(os.path.dirname(__file__), "data/ogs.sgf")
tree = SGF.parse_file(file)


def test_kgs():
file = os.path.join(os.path.dirname(__file__), "data/kgs.sgf")
tree = SGF.parse_file(file)

0 comments on commit a3e12e3

Please sign in to comment.