3 // Quick and dirty SGF parser.
6 var $sgf, $index, $root;
10 $this->tree
= $this->parseTree(null);
12 function parseTree($parent) {
14 $tree['nodes'] = array();
15 $tree['trees'] = array();
16 while ($this->index
< strlen($this->sgf
)) {
17 $char = $this->sgf
[$this->index
];
21 $node = $this->parseNode();
22 //if (is_null($tree['nodes'])) $tree['nodes'] = array();
23 array_push($tree['nodes'], $node);
26 //if (is_null($tree['trees'])) $tree['trees'] = array();
27 array_push($tree['trees'], $this->parseTree($tree));
36 function parseNode() {
41 while ($this->index
< strlen($this->sgf
)) {
42 $char = $this->sgf
[$this->index
];
43 if ($char == ';' ||
$char == '(' ||
$char == ')')
46 while ($this->sgf
[$this->index
] == '[') {
48 while ($this->sgf
[$this->index
] != ']' && $this->index
< strlen($this->sgf
)) {
49 if ($this->sgf
[$this->index
] == '\\')
51 $values[$i] .= $this->sgf
[$this->index
];
55 while ($this->sgf
[$this->index
] == ']' ||
$this->sgf
[$this->index
] == '\r' ||
$this->sgf
[$this->index
] == 'n')
58 $node[$key] = count($values) > 1 ?
$values : $values[0];
64 if ($char != " " && $char != "\n" && $char != "\r" && $char != "\t")