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

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_gram-0.3.6.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.6.tar.gz
Algorithm Hash digest
SHA256 31c126d894f2e24644d5b4ffd67fef26264e81b421e9343abbc62a2bb2b00db8
MD5 b2cfbddfd56cb1285a3bf5c04ac2b183
BLAKE2b-256 bac62ae588f6990ebaabfa0a863bb67857928b76bd36ce3d0d793d5d8b72f13d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 570b2934ba106913b56ded0c6f5c92a54ce70e9180d95e81007ae0f4fb566283
MD5 f34c04ec18ae9e4f4b96ecbb06afa424
BLAKE2b-256 9463664cbb424629b27b8d84ce4a9c9a67d6a8c8e5afed8509b56667b3df4c8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2ecf03e54a6069f39658de1fc64d57b123b185479cd2e3719a46f98df6bc387b
MD5 a6b1ef1d42ff487fa152efcdeb7b44f0
BLAKE2b-256 097ac98cec0e503aa7aed7a662e8b341de308ca9537a4207ac5543ee611dc09d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9b42a95deeca4fab43bab7a0cd74d2b996b303f88ce4dec708c7e194395ddc98
MD5 8d01cc206aadee67411294a4c9b7ab42
BLAKE2b-256 c6ce46af90c226ae9250667da0b37dfa8e6ba07665682c824aa49375dbddcf12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b584c6658fb85836cd6c690a9834e5ad10da92916cb81b8f2524ab10740105c2
MD5 b4ca07d2cae26050bec17a5ed4f21301
BLAKE2b-256 0e09527613151d7cfc69beef145f4d74e61de7f4799ad59231ce8f9168f7b207

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 20711d802ad182e857e5f22aa6fd8e3072389b377f88bbfd72a3a4d27e239d3f
MD5 cb44e2afe642ec2a8f159d7eab3d0247
BLAKE2b-256 cec69cd949e7096d72d20a7511d2b5c0982a148c00540d609d401d2a6db7de4d

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.6-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.6-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 7476e2554571f4f36ebdeb186cac4a1ed49cb1c844899e7c4edcc57a4947544f
MD5 56f820afbdeeb4d60b788c6d46760486
BLAKE2b-256 041075af3676d2d2412afa98217d0ab350ccf92079c60223b88aea99f85c5597

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c05e33a533f8873e2491bf2704c38de1395930e41777835a6d07128ba0eb924
MD5 a5a04cdd0496e32f8cc58b52bc2c0bd0
BLAKE2b-256 74a395c71fa1ee3f6a5775f8e63eddbf926fbf1d7ef130316532bfe996b670a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.6-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5f774b4b668a55a77853dad49cc9583c189ac783ce2d2deda30f77e7ce7339f1
MD5 538c5cd21262a056f49192770f96ee38
BLAKE2b-256 4a71e6a1aa5841d17e03d23b5b50dda95140daec434189fa54092392cdee687d

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