tree-sitter-sgf
This grammar implements the Smart Game Format, SGF. It targets FF[4] standard, and has limited support for the older versions. It supports Go and other games.
Development
Install dependencies, generate the parser, and run the public corpus tests with:
npm install
npm run generate
npm run check
Installation
Install from npm:
npm install tree-sitter-sgf
const Parser = require("tree-sitter");
const SGF = require("tree-sitter-sgf");
const parser = new Parser();
parser.setLanguage(SGF);
const tree = parser.parse("(;GM[1]FF[4]SZ[19];B[pd];W[dd])");
Install from crates.io:
cargo add tree-sitter-sgf
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_sgf::LANGUAGE;
parser.set_language(&language.into())?;
let tree = parser.parse("(;GM[1]FF[4])", None).unwrap();
Install from PyPI:
pip install tree-sitter-sgf
import tree_sitter_sgf
from tree_sitter import Language, Parser
language = Language(tree_sitter_sgf.language())
parser = Parser(language)
tree = parser.parse(b"(;GM[1]FF[4])")
The grammar follows the SGF FF[4] syntax definition: a source file is a collection of one or more game trees; game trees contain sequences, nodes, properties, and bracketed property values. It intentionally does not validate SGF semantics such as property placement, point coordinates, move legality, duplicate properties, or game-specific value formats.
Helix
For local Helix testing, point Helix at this repository in
~/.config/helix/languages.toml:
[[language]]
name = "sgf"
scope = "source.sgf"
auto-format = false
injection-regex = "sgf"
file-types = ["sgf"]
[[grammar]]
name = "sgf"
source = { path = "/absolute/path/to/tree-sitter-sgf" }
Then link the Helix query set into Helix's user runtime:
REPO="$(pwd)"
mkdir -p ~/.config/helix/runtime/queries
ln -sfn "$REPO/queries/helix" ~/.config/helix/runtime/queries/sgf
hx -g build
hx --health sgf
queries/helix/highlights.scm intentionally duplicates the shared highlight
query instead of using ; inherits: sgf. When the Helix runtime path is a
symlink named sgf, inheriting from sgf would inherit from itself.
Neovim
Neovim uses queries/sgf/highlights.scm. The Helix indent and textobject
queries are kept under queries/helix/ and are not required for Neovim.
Build a shared parser for local testing:
npm run generate
npm run build:parser
Register the local parser, filetype, and runtime path with the example config
in editors/nvim/init.lua. When copying that file outside this repository, set
TREE_SITTER_SGF_REPO to the repository path or replace the sgf_repo value.
Smoke-test the local Neovim setup with:
npm run smoke:nvim
If you have a local untracked SGF corpus under corpus/, parse it with:
npm run parse:corpus
References
Metadata
Release files for tree-sitter-sgf 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tree_sitter_sgf-0.1.0.tar.gz | 14.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tree_sitter_sgf-0.1.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 22.9 kB
Release files / tree_sitter_sgf-0.1.0.tar.gz
| Download URL | tree_sitter_sgf-0.1.0.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9c0f82343323de2cd105c42234ab7f908f80d4088bd1379113eb52bcf1cf6e1
|
|
BLAKE2b-256 checksum How to use checksums |
b1b1fc2c26b3f9d1335dbeddbd8caedd6ab2459855b446630e8b1771071b998c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|
Release files / tree_sitter_sgf-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | tree_sitter_sgf-0.1.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.6 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8dea68b38501f2ebd2c1090cf4abb1a57bde3e82d2a3abcb2773d9de6afe39bb
|
|
BLAKE2b-256 checksum How to use checksums |
b44b640e34532a467080df21aa201a4c5487e40a11606be7d549bc4ab78758fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|