| Crates.io | tree-sitter-gram |
| lib.rs | tree-sitter-gram |
| version | 0.2.7 |
| created_at | 2025-11-25 16:48:53.690417+00 |
| updated_at | 2025-12-06 11:57:34.834403+00 |
| description | Gram grammar for tree-sitter |
| homepage | |
| repository | https://github.com/gram-data/tree-sitter-gram |
| max_upload_size | |
| id | 1950076 |
| size | 222,802 |
A tree-sitter grammar for gram notation.
Gram is a pattern-based notation for structured data.
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.
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:
(): A pattern with 0 elements.@a (b): A pattern with 1 element.(a)-->(b): A pattern with 2 elements.[ s | ... ]: A pattern with an arbitrary number of elements.A path is a flattened tree of relationships. For example:
(a)-[r1]->(b)-[r2]->(c)
// is equivalent to:
[ | [r1 | (a), (b)], [r2 | (b),(c)] ]
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"]}]
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
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)
]
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.
This repository includes editor integrations for syntax highlighting and language support:
See editors/README.md for installation instructions and available features.
Tree-sitter bindings are available for multiple languages:
npm install @gram-data/tree-sitter-gramCargo.tomlpip install .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.