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

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_gram-0.3.9.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.9.tar.gz
Algorithm Hash digest
SHA256 097f6f9547efc9409333d3f33fcbf9aae481834919e8e36d67128147b55748c2
MD5 5d5b14228efff02d3a37b24e32f91499
BLAKE2b-256 07b3d54acfefabbadd332f0c1b8ff5119a475f8955abd3be53b5b83c9b158286

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 8092bd92e23d8905fbac0050299bd4e65f44bbee0d87d40555b449314c044132
MD5 eb185f4e33f1fcd66a3243d961e58323
BLAKE2b-256 2a2f3ba597f62cf9d691605ebc72e6a6320920a641929f0814da5f287e80b626

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c0ed6d15ed70e10e49cf38a7b61e6ee5f6b6e7cbb37fc79d3486ab0501e804ed
MD5 dfdd4bdd3f066cb92b80820208fdc6a8
BLAKE2b-256 32410a148b48ed30b0bc6e2031dd94f190698927392ef710782731e8397faffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9cb816e40e73826cb7b6f07535291c6bd858b708a43e56b8957dc230168f8ab7
MD5 708b8b7e1640132393fbef226866ca4a
BLAKE2b-256 5f1c35db213b968a26bd2f710c2a51b3c10aff81eb30d375ebef1f16c4e10c46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 25ced4c90e3ce1f1cf3b9751a9c823994b95171181f35d4b13c95488fd93f567
MD5 173a29164dd89be1cc2a596e0c8ac801
BLAKE2b-256 09e5ca6a7ca167838ad8194a2c162896d457fdd78923b72b6c442df322cc3084

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a0c98c8b936a6823d36788634a9cf976417297714c0d2e4acac763a2031518f0
MD5 d7139a2f2d722c76af0fc9fa580b3f21
BLAKE2b-256 1666e5ce047ea1d51d5ed9255c0b6e8b0aa0c2cb1bd651ad8fb573181133088e

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.9-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.9-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b3ed49bfa12103cc109e80f731053d4b62274d2d917dc0aed03bae8be6a1e554
MD5 9c5c7d6a968cd7543c7c80ccd7f24b92
BLAKE2b-256 0e5ef8df843e99c6692415e2de079ac0b5485b7de0e0411a62eb2b23d37f5564

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 135376b25c96ccac5c53b53e39fec530ca292487e00583516c4932cfb4f783d6
MD5 cbbdeb3d38591237c1f9fc6b1c0e28d7
BLAKE2b-256 4f282e88c2823033b8c83d250d9d0ef18315e4236dd75f02c6fac01bdb583036

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.9-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b2c828b89e1f3b09a0dc1bb1bed35e7bc5783717f9b40578da1b8654ede8e56c
MD5 a32c84cb66db2f035a005788e05df0cb
BLAKE2b-256 437ea39ad702ee7128232b4bb7db74936093269c5485ff169ef6676bd12633db

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