Skip to main content

Tree-Sitter TOON Grammar

A tree-sitter grammar targeting TOON specification 4.4 (October 8, 2026), with syntax highlighting queries for editors including Zed (toon-spec: 4.4).

Installation

Python

pip install tree-sitter-toon
from tree_sitter import Language, Parser
from tree_sitter_toon import language

parser = Parser(Language(language()))
tree = parser.parse(b"name: value")

Development

# Generate parser
npm run generate

# Run tests
tree-sitter test

# Parse a file
tree-sitter parse example.toon

Features

  • Full-line comments that preserve indentation scopes
  • Arrays with comma, pipe, or tab delimiters and nested delimiter scopes
  • Keyed tabular objects, including root keyed tables
  • Recursive field groups in tabular and keyed headers
  • Bare empty arrays in fields, at the root, and in list items
  • Decoder-compatible literal keys and unquoted strings, Unicode, and \uXXXX escapes
  • Arbitrary literal header and field names, empty keys, and spaces before key-value colons
  • Quoted spans inside unquoted tokens, literal quoted controls, BOM and CRLF handling
  • Objects, list items, quoted strings, numbers, booleans, and null
  • Correct sibling scopes after empty objects and list-item first fields
  • Highlighting, bracket matching, and indentation queries

This grammar produces syntax trees for editor tooling. It is not a TOON decoder or strict validator: declared lengths, row widths, duplicate keys, numeric range, and configurable strict indentation checks belong in a decoder or validator. Indentation widths are inferred from nested scopes, including custom widths. Blank lines and some non-strict indentation forms remain accepted for editing. Dotted keys are literal keys; v4 removes key folding and path expansion.

Malformed headers such as foo[03]: 1 are syntax errors under 4.4, including in non-strict mode. Quote the key ("foo[03]": 1) to use it literally. Tables require field lists, and keyless fields-bearing headers are allowed only at the document root. An empty unquoted key has no key child in its pair or keyed_row, just as empty cells have no value child.

Verification

tree-sitter test
python3 test/check_v4.py
# Corpus, native Node binding, and editor query checks
npm test

The corpus includes all 246 valid decode cases and 160 encoder outputs from the pinned TOON spec v4.4.0 tag (revision d09c3d33e37389345a74bd96981eb96dd9be6c5e). Exact-input checks preserve missing final newlines and control characters, reconstruct fixture data from the syntax trees to check scopes, and verify malformed syntax, token classification, custom indentation, and incremental edits. Fixture sources and their MIT license are in test/fixtures/. The Node binding requires the Tree-sitter 0.25.x runtime.

To refresh the pinned fixtures and corpus snapshots from a spec checkout:

python3 test/update_spec_fixtures.py /path/to/toon-format/spec

Review the generated snapshots and run the checks above after importing. npm run generate preserves the separately maintained vendored C headers while regenerating the parser and syntax metadata for ABI 15.

Documentation

  • example.toon - Working demonstration file

Test Organization

test/corpus/
├── arrays/          - Array tests (inline, tabular, list, root)
├── objects/         - Object structure tests
├── delimiters/      - Delimiter-specific tests
├── spec/            - Pinned TOON v4.4 decode fixtures and encoder outputs
├── comments.txt     - Comment and CRLF regressions
├── primitives.txt   - All primitive value types
└── mixed.txt        - Complex combined scenarios

Example

# Keyed tables can share a nested field structure.
servers[2:]{host,geo{lat,lon}}:
  alpha: a.example.com,50,10
  beta: b.example.com,40,-100

name: TOON Parser
version: 2.0
unicode: Hello 世界 🎉

arrays:
  inline[3]: a,b,c
  empty[0]:
  
table[2]{id,name}:
  1,Alice
  2,Bob

users[2]:
  - name: Alice
    score: 100
  - name: Bob
    score: 200

nested:
  data[2]: x,y

License

Licensed under the MIT License.

Metadata

Release files for tree-sitter-toon 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-toon 0.3.0
File Size Uploaded Provenance Actions
tree_sitter_toon-0.3.0.tar.gz 39.5 kB Without provenance Details for tree_sitter_toon-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-toon 0.3.0
File Actions
tree_sitter_toon-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for tree_sitter_toon-0.3.0-cp310-abi3-win_amd64.whl
tree_sitter_toon-0.3.0-cp310-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.17+ x86-64 Details for tree_sitter_toon-0.3.0-cp310-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_toon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for tree_sitter_toon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
tree_sitter_toon-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details for tree_sitter_toon-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl

Total release size: 159.8 kB

Release files / tree_sitter_toon-0.3.0.tar.gz

Download URL tree_sitter_toon-0.3.0.tar.gz
Size 39.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b74b461b23c6d1d2d79269cb7560962f03ef208c11ff9714e403121bfd254bea
BLAKE2b-256 checksum
How to use checksums
d8dd08eadc2d9cb332abe15e5e4b5695b64241bab7f355ec661e2d09c9001c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_toon-0.3.0-cp310-abi3-win_amd64.whl

Download URL tree_sitter_toon-0.3.0-cp310-abi3-win_amd64.whl
Size 25.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3b2318a72de6afe3d957a9b8309363a449a63a9a9b72b61d71eb8316027a0349
BLAKE2b-256 checksum
How to use checksums
a15e3dc35b813cd2d4405288345bd888c907b6da6b7f2d7558cc5bad1d4c119c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_toon-0.3.0-cp310-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_toon-0.3.0-cp310-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Size 48.3 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
c1c8566afc1989fd57cf26ae2a28a522b10c5bb30870d3a662338ac7a1b2bf5d
BLAKE2b-256 checksum
How to use checksums
4ce50ce6744f666584ff918a5f79d0a479bb5d2530796dd3674ad70963660adb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_toon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_toon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 23.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
81914afcffe2b042c1af9e34699061e56aa1186a4bd203fa5cc23b91de579535
BLAKE2b-256 checksum
How to use checksums
f899a55409d716a016f1f22bda920d0701206f9390e355d574a7fa921f6be0cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_toon-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_toon-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl
Size 23.3 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
5ca27a43535cd4d7ba915ed1e50e5eee0933f60723fad20f67abbee1593841f9
BLAKE2b-256 checksum
How to use checksums
c111e64c17dcfd448787875b8f38167483faf8ce5e77b4b7229945678c8ebb33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tree-sitter-toon 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page