Gram grammar for tree-sitter
Project description
tree-sitter-gram
A tree-sitter grammar for gram notation.
About Gram
Gram is a pattern-based notation for structured data.
Patterns and Subjects
A pattern is a generic data structure with a value and nested elements:
interface Pattern<V> {
value: V;
elements: Pattern<V>[];
}
Gram patterns are always Pattern<Subject> — patterns where values are subjects.
A subject is content combining an optional identifier, labels, and/or a record of properties.
Pattern Elements
The gram_pattern (top-level structure) consists of a sequence of patterns. Syntactically, subject_pattern, node_pattern, relationship_pattern, and annotated_pattern are peers.
They correlate to the underlying data structure based on the number of elements:
- Node Pattern
(): A pattern with 0 elements. - Annotated Pattern
@a (b): A pattern with 1 element. - Relationship Pattern
(a)-->(b): A pattern with 2 elements. - Subject Pattern
[ s | ... ]: A pattern with an arbitrary number of elements.
Path Flattening
A path is a flattened tree of relationships. For example:
(a)-[r1]->(b)-[r2]->(c)
// is equivalent to:
[ | [r1 | (a), (b)], [r2 | (b),(c)] ]
Subject Pattern Notation
The subject pattern notation uses [ subject | elements ] to explicitly show pattern structure:
// A team with members as elements
[devrel:Team {name: "Developer Relations"} | abk, adam, alex]
// A simple atomic pattern (no elements)
[:Person {name: "Andreas", roles: ["author"]}]
Node Notation (Syntactic Sugar)
Parentheses ( subject ) provide familiar graph node syntax:
() // Empty node
(a) // Node with identifier
(a:Person) // Node with identifier and label
(a:Person {name: "Alice"}) // Node with identifier, label, and properties
Relationship Notation (Syntactic Sugar)
Arrows connect nodes to express graph relationships:
// Path notation for graph relationships
(a:Person)-[:KNOWS]->(b:Person)
// Subject Pattern notation can contain path patterns
[social:Graph |
(a:Person {name: "Alice"}),
(b:Person {name: "Bob"}),
(a)-[:KNOWS]->(b)
]
Comments
Gram files support comments using // syntax:
// This is a line comment
(hello)-->(world) // End-of-line comment
Learn more about gram at the gram-data github org.
Editor Support
This repository includes editor integrations for syntax highlighting and language support:
- Zed Editor - Full syntax highlighting and language support
- More editors coming soon! Contributions welcome.
See editors/README.md for installation instructions and available features.
Language Bindings
Tree-sitter bindings are available for multiple languages:
- Node.js:
npm install @gram-data/tree-sitter-gram - Rust: Available via
Cargo.toml - Python: Install via
pip install . - Go: Import from this repository
- Swift: Available via Swift Package Manager
- C: Build with included Makefile
Development
Generate the parser after grammar changes:
npx tree-sitter generate
npx tree-sitter test
Run language binding tests:
npm test # Node.js bindings
cargo test # Rust bindings
python -m pytest # Python bindings
make test # C bindings
See DEVELOP.md for detailed development guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_gram-0.3.4.tar.gz.
File metadata
- Download URL: tree_sitter_gram-0.3.4.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1118d987f94ecc08309de54dbc3478014c739043ec3d033aa01140a752f4977
|
|
| MD5 |
c365ff6b723f94e219e3b802c17f1f91
|
|
| BLAKE2b-256 |
d0f53770450860c87ce406c6bd0ab8635e31ce64a67c37ead78fa2bcf992b9c5
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-win_arm64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-win_arm64.whl
- Upload date:
- Size: 18.8 kB
- Tags: CPython 3.9+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16de78305bfacf88bc5a92dccfc14b3ef1e91470f3ec7e164ca947f5697354e2
|
|
| MD5 |
3e9ec22ddf7e92d859cd73b6fdffa5c1
|
|
| BLAKE2b-256 |
907a1151c3bef5694c4939fb3e150bccaba5a130f473bb5908a5146918b28467
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 20.0 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bfa986706854a623dd80b8b082f0a8057f4b691cc12dd77c43e58157bbb508c
|
|
| MD5 |
ef574633ebd16b593837ef2944454aff
|
|
| BLAKE2b-256 |
d46734f8a1f1d2a160d0940336c4f37e44acf18da71dbeee2260b0a13b963147
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 30.1 kB
- Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d2e859bcb8395903f82edb77f2177545c99329b11e8172bc27d340e0600e720
|
|
| MD5 |
6cf7568acdf291d569280535478ae1ba
|
|
| BLAKE2b-256 |
477452bfaa0b055cac471ae954cbffc673d4c257e348f9067f35dc3cf7389053
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 31.1 kB
- Tags: CPython 3.9+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78f4c98885c53c1c52373df39e12034b1559a65c251e1f9dfa23abb130e08d79
|
|
| MD5 |
f697c51b0ac70757e2aa850621098c4e
|
|
| BLAKE2b-256 |
d92b41eaa058c999bdbfc2db2f2f5a6758d249e3758503989bbd11bb2e29b504
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 32.1 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
006700b5fb9cf580940df22bd270947f7291f4becc3df52148bb80d3fa302067
|
|
| MD5 |
297358596022e85a34b14952784f54fa
|
|
| BLAKE2b-256 |
508961531f6ac2e36f524560c43cb2c1b6775b51a9df7022525c69a7fd3167ed
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 30.4 kB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7f3f4f18cb52cad2c0eaaa23716d614ec887a47258327956daa758c9a5a28b
|
|
| MD5 |
9f9b9d1e831e0d369db48b2bf0a467b5
|
|
| BLAKE2b-256 |
469a63f692ddd89a482c470213eb61aa228c9442ed372c4947e3861fbe01848e
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 18.4 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2b044e1f7a4f87bd709d1ae173401006ffd0b840b61426394aa2c96951eeb6
|
|
| MD5 |
f11016ee001d8209eca5c5b61cc80349
|
|
| BLAKE2b-256 |
baad7a556ba5102da7040d7e768dbdcff9a895b653f6d230b28c3ec6f7ad5a86
|
File details
Details for the file tree_sitter_gram-0.3.4-cp39-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: tree_sitter_gram-0.3.4-cp39-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 18.0 kB
- Tags: CPython 3.9+, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
664f496eb21be8cd48efdffd504e130378d58020b943f878bad19bf89c465479
|
|
| MD5 |
001a0517efee45af945cca0e937adfcb
|
|
| BLAKE2b-256 |
b1010aab95e00b9a659f3aaed4995f5ce992c22011800db15cf2508959c84d55
|