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.7.tar.gz (19.4 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.7-cp39-abi3-win_arm64.whl (19.1 kB view details)

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

tree_sitter_gram-0.3.7-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.7-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.7-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.7-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.7-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.7-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.7.tar.gz.

File metadata

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

File hashes

Hashes for tree_sitter_gram-0.3.7.tar.gz
Algorithm Hash digest
SHA256 003bb4f1b0a58b3c340fcc87e6e228a0ed9799f369df34e9520305ad8b652d47
MD5 ad381cdd4de464283a50b42c7813387a
BLAKE2b-256 c1bc414e0779817a024a1c42e95824b978768838628b60a1562fa85810f113a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 dd5036e08441588e5ff48e0825fbc6f9397d5ca70b7b65d38571a9ad3963cc00
MD5 147284c605e015f81b3044683167c060
BLAKE2b-256 5e1bcfff92d1ee02a5a97370454de7783e7c2190dfc522124373863435ec0780

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1a11e8b1a9c9ec20c9bd81a1a8155ff4771fbf8c32e7cddcbe04cad6d3c38093
MD5 0ba82b62879a4fa29ab4d288b0c2deb3
BLAKE2b-256 412ee19ee9683f12729cf62ce67b9e8c2ce2b9b14baea04e7973da826edd5e2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eb6501175f6b3bc7e842500841d33f7fb67372076985a86ce1292f06bb4b592b
MD5 1a19e519f8052d6ef4e3123975f6a66d
BLAKE2b-256 0e9116aef30cc80f6ac10dd0dae5fe29a56fbe086ff193641096c26d5755a5aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5cf75d6549b2313370121540c76c837fb024dda57656a51e6cb74344cade3ef2
MD5 ddc57c8897ff0a185d752fb73aea081e
BLAKE2b-256 e1d3f4de3181550181a5703a9efdfe861b2a98e95acc52e2edf2297a4db90aed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 acff2614dde6ba9132888ae17659cd5b1ff5812a495cf84fbe91a49ca4a397f8
MD5 3d59c4d9bdbe4f3877cf75a708fc4ae1
BLAKE2b-256 a8a8e9428f05fa83320094bbb51427191c3f35a4ca111065086d984538053d01

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.7-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.7-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 34f6dabf5f3f291a51876af710cec22198e838e76458bdbf6ec5612e511b5c26
MD5 018fe7c1a926f5473a165c6252b178e2
BLAKE2b-256 e7ebb55170a75e5300dd3aaa8be04a53dc9e0317ecb6f7dfe207d12f309a10f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 700a74ff66c04c3b8aacdc2242651f8fae17d323ce1b46fe74ca76d72b0a99dc
MD5 17942aae73244848d0bd69f340bac255
BLAKE2b-256 7bdf43d8d25c3659a65b1c56e980d834cae09a4ffa36bc43b578096fe818f330

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.7-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 517af155f5537ba5da2500916ae4812796d8e55f7b4edc6a53f83d2541b90405
MD5 3a2092c21a2e481371f0adea5aec868b
BLAKE2b-256 2432b250dc7d882616ede1b4ceacb0ce44ea9d0f2340766593aa78fadf661794

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