Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_gram-0.3.5.tar.gz (19.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_gram-0.3.5-cp39-abi3-win_arm64.whl (19.1 kB view details)

Uploaded CPython 3.9+Windows ARM64

tree_sitter_gram-0.3.5-cp39-abi3-win_amd64.whl (20.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_x86_64.whl (30.5 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_aarch64.whl (31.3 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

tree_sitter_gram-0.3.5-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (32.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_gram-0.3.5-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (30.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_gram-0.3.5-cp39-abi3-macosx_11_0_arm64.whl (18.6 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

tree_sitter_gram-0.3.5-cp39-abi3-macosx_10_9_x86_64.whl (18.3 kB view details)

Uploaded CPython 3.9+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_gram-0.3.5.tar.gz.

File metadata

  • Download URL: tree_sitter_gram-0.3.5.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_gram-0.3.5.tar.gz
Algorithm Hash digest
SHA256 309f9b132736e8bb78e57a962c565b4932e865ee7ed3c903308e567cf51d3b89
MD5 d1b1342ea770ca7763e747eaa31e3bc6
BLAKE2b-256 b951064a83af3a4b39545583de913b6ad41df9f56d179cd36efaaabbd70c9633

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 db06405ecf5ac62e73f7e5c9c333e8f933de456adae39291b1db835215803140
MD5 02eb095ce2ff31f4f15ba0dbb0aaacfd
BLAKE2b-256 7cf91b64bcf481619b7319058443ff89a69f1775ef69c990429f4bd4cd9e8235

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9890742c2e7afcc4bbdc3d76d5cac23ab45fe985f380de45d1d3f5525b57873d
MD5 2bf828ad15cfb7df45e9c4dfb874ac80
BLAKE2b-256 b7b6a0f771eab0339f61d684062a889b70053de7db80f67e69471d7c6b5a2810

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 84f5e4373effc874ffbe5e0d7c9c33d672ddba0675c0d1ddc9a50a63fb16fd6f
MD5 50499de4c2011b8c5f5c2d6c86545685
BLAKE2b-256 937626dd559e0851e975dac242df24899c8562c7fe22b28eaf97f5f1a137dc14

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c0405704b86b889b316b5795cef12ef53af60a205c0957a20a365b3bcf4f8770
MD5 94742bf8aa046c71a5d8ec3a15cf5c67
BLAKE2b-256 51595bf4dab7290bdbc0ca34d0d8dbab9a9a9dbd5eb7c93514a36da7b5267c22

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0712d5453695cbe1cc9176e091d4f5c739b006b2f1565d75f409764398b3154a
MD5 c86ab19199d61317d44f05912c27ba1c
BLAKE2b-256 0b44090f39e50923b49ad66e5395cdf2b3e5091dfd970da5f92780af8146e7b8

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2270b8affeedbfc6e7a12703a8d96bdd4ea65ab6d87fe46628a8b55ca4429310
MD5 c27be02865e1d33746fd88cf357986b2
BLAKE2b-256 934cc6b8b2271ae623300032c87e1ff660be918eeab7dbc3c67d8f67d9357e13

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8082fbbeda9629f3b69f7c735f39a90ccbba7da20398ce05825d3c47dcdde30b
MD5 21feb97f0d0195f2d23d4a501ea55ad6
BLAKE2b-256 1119f55d8e0cc71291190e81c8bc233e929e3814b3393aa9a6c880c474cfc3c6

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.5-cp39-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.5-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 50f91b1183a3b6230d288119e9d56a3755476d76203769568dc4a09a95b5179f
MD5 5fa736a29aa8386263788457a12e7dee
BLAKE2b-256 74ec5b9c9516efe67e22095e1d62d3900e5954df62b7df79827eb2b03900c1e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page