Skip to content

psygo/sgf-tree-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SGF Tree Parser

An SGF is basically a text encoding of a tree data structure, and its grammar is described here.

Usage

Basic parsing:

import { SgfTree } from "../sgf_tree"

const sgfTree = SgfTree.parseSgf("...")

The tree's type is equivalent to this type in the end:

type SgfTree = {
  data: SgfProperties
  children: SgfTree[]
}

Some useful methods:

tree.toSgf()
tree.toJson()
tree.toPrettyJsonString()
tree.toArray()

Typical SGF tree operations:

const newNode = new SgfTree({ B: "jj" }, [])

sgfTrees.add(newNode, {
  down: 3,
  right: 3,
})

sgfTrees.remove({ down: 3, right: 2 })

sgfTrees.shift({ down: 3, right: 3 }, true)

You can find out more about how to use these methods from the test files.

References