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

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_gram-0.3.11.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.11.tar.gz
Algorithm Hash digest
SHA256 0fdf95f976c801cf4f32dbcc7ff9fd13d33812e06ceb9c67f8024ae38b5299fc
MD5 2fa2be3c2939c778daebaf0af0332fb4
BLAKE2b-256 94cf87b592495ed5cae92228a4bb930672807fa3b7926ea45eb6d2be794193af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 fd6cdecfff00b8bc59241505b5d5c956ffbd52c5b922cd7008f796e6961bf4e2
MD5 0133402529b7dbffb465eece13a66e44
BLAKE2b-256 e55d2976a8272f204d5270b529204ce91230e34759eadb215cddcf5e99c0e0c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dc708807f4e3092617c05fd64d575c4ff3842a004ed86824f1507cf95491c686
MD5 c882864761433f3266d75e124e330ec7
BLAKE2b-256 7243a7ce7d465d61f1560ebb1643190181428bc0a46296b7781af2cfc3051e7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 acb10b8e19ac0ab293e9c77d9a832aa8d717c66dd1123dc8be180b53577b010e
MD5 fb02ebad433f4972f375c421cb907ea6
BLAKE2b-256 8c2ce707a0de5b47c158c16346c6bddbea0f220d38640a482ac1f5f6b888e041

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f676f39292da7d531c2a8a008d6fca49c5965087fb0a34bdf052ecc415bd5a05
MD5 4c211f2f3608460f710cf566f3d62a9b
BLAKE2b-256 ec3bd126999d6d6e208c97f88e861445624387624a82eea9fdfcbab570f19a99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6815695fb002e8d1bf6dd0f50f21151fefcf4006e2059c670dac041e7366d93d
MD5 13781252c25fcdab4536eed2588b1044
BLAKE2b-256 fda1d8cdae193c513057a3b85f73904fb70814e68d4e9b172909bc0bd456628a

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.11-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.11-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 05cc2f58d718e6b421ede89621f06911b5bb2e44ce62a0860b7a83f1a6666fe8
MD5 e8b8897f71a1bfe390813692c36a06f5
BLAKE2b-256 da656170923c910f583178e86c6fe8ccbe51c0e184a0d9e1edbe19ac462cbccf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 387e040be17d9e796f02704338bff40f3461e3d2682de2900e864767db4bbcbf
MD5 673e1ff14ee10c9c33f37c70dcd50be6
BLAKE2b-256 a6732ff38763eb9d3af01933ab06f222025aff5574eed794d62aa8377d696360

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.11-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a8787a00f55afb6151b773983cbbef6fec9295a7b0861e1e153a867c76241bb0
MD5 ebb0b5175889086a3cfcd393c0c7416f
BLAKE2b-256 c0a79ba2daca26d7d0f0b8c5039ddb71e4fbd339fc19041948257e31e87af6fa

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