Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psygo/sgf-tree-parser
A readable SGF tree and parser
https://github.com/psygo/sgf-tree-parser
baduk go igo sgf tree weiqi
Last synced: about 1 month ago
JSON representation
A readable SGF tree and parser
- Host: GitHub
- URL: https://github.com/psygo/sgf-tree-parser
- Owner: psygo
- Created: 2023-12-26T00:11:30.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-04-27T12:54:56.000Z (8 months ago)
- Last Synced: 2024-05-02T00:22:10.963Z (8 months ago)
- Topics: baduk, go, igo, sgf, tree, weiqi
- Language: TypeScript
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SGF Tree Parser
An SGF is basically a text encoding of a tree data structure, and its grammar is described [here](https://homepages.cwi.nl/~aeb/go/misc/sgf.html).
## Usage
Basic parsing:
```ts
import { SgfTree } from "../sgf_tree"const sgfTree = SgfTree.parseSgf("...")
```The tree's type is equivalent to this type in the end:
```ts
type SgfTree = {
data: SgfProperties
children: SgfTree[]
}
```Some useful methods:
```ts
tree.toSgf()
tree.toJson()
tree.toPrettyJsonString()
tree.toArray()
```Typical SGF tree operations:
```ts
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
- [Go Pattern Search](https://github.com/psygo/go_pattern_search?tab=readme-ov-file)
- [Sabaki's SGF Parser](https://github.com/SabakiHQ/sgf)
- SGF Docs
- [Red Bean - SGF](https://www.red-bean.com/sgf/)
- [CWI - SGF Format](https://homepages.cwi.nl/~aeb/go/misc/sgf.html)
- [Stack Overflow - How to Parse SGF Metadata with JS Regexes](https://stackoverflow.com/q/77717462/4756173)
- [Stack Overflow - Recursive Regex for Parsing SGF with JS](https://stackoverflow.com/q/77718740/4756173)
- [Peg.js - A package for parsing any grammar](https://pegjs.org/)
- [LaTeX Stack Exchange - Parsing the Main Branch of Single-Branched SGF Files (with Regex?)](https://tex.stackexchange.com/a/709698/64441)