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

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_gram-0.3.10.tar.gz
  • Upload date:
  • Size: 19.5 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.10.tar.gz
Algorithm Hash digest
SHA256 815ab34fc917a894e6b9f72179e2b849a3d376a65edd910e11bdd88e39a417e6
MD5 8881fda8fdf43f454f8e90bd0876b5b5
BLAKE2b-256 31893363a10c5287b5603d1c781eb4af73b701be30637890c30e399982bb5c28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cad4b27eab8042ba8e4c6b9b8a4dd3a46b8160b23518089e4860b69c3cc88b6d
MD5 a4cf63578f9fa6fd38ede2efb07064cb
BLAKE2b-256 543e033eae4f063ffbf2953fcf01678415a705fde74666e72fea5b446f2cf8be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f5924e067f240f01b9b9d30e234d0d1c7a5631eb28ba081a8e88f047834057e5
MD5 d09cdb3f2b78b6cdf0da7821a18bc3f1
BLAKE2b-256 4f2594c7a992421ee6142dda4d9e67d0333f866cac6afd47578deb3a35d43450

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dab5bc88ed65a0c40df38ec56fe6cc8b43d8237aeeb2ef6e76fa8e8db4d82056
MD5 d61179ef980808003de36f12a3e50b66
BLAKE2b-256 200d458c4f7d090602d8b2566b06ff51b3ad938bd0d693a7f11a4b51c7c39535

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e0d9dd65294b860cbc4546c0d81d6aaacd370cd57be95ace34bb42570990223f
MD5 b882b27c85274a793b489c372d45be5e
BLAKE2b-256 afb63d6d4ef4386739a434e3ec019a07d46a7ba76e3df4dc9267bd40ec7582a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ba26f63f790499ceb6b6b0ab48c94a63a8097b8904990e787af84fc01999ecac
MD5 d2a0a1f32373cf71e37af8839a1d6a30
BLAKE2b-256 38d2d358aab5d7e758589107b78e98eab4c1f9cf3fa6b8e3f644d9412b2252aa

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.10-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.10-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 3f5ecae29fd34d0cd76607bf2b08bc326306e10d25d30ac9c1fac5d28a378b32
MD5 035002e5f137fed23b0e5ae8adfd994e
BLAKE2b-256 76c688f5da26b1a8d9c1e781bbf9d91d71f3991fe7c68d6ab7da75f3aa7e20c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bc0e32e6701426267f0cf7366a4aba2e435cc745a97d8edae43e97d89045265
MD5 85901f2fd928c0dbb7244fe3833bef33
BLAKE2b-256 eda3cafeda97e6ca60929e87e8e8cdb068f4592c04a8075bc947ba07ba423713

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.10-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bf51290b130e227a5e718936dd06b5b399f405cbca0c948cdd308fa7ea324e8d
MD5 d679cd8c714098abb28a0324edbe6b46
BLAKE2b-256 eea99a551dea36d6cc730a63aaed1a40cb4f62211941d08e90baed8e28fe9056

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