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

Uploaded CPython 3.9+Windows ARM64

tree_sitter_gram-0.3.3-cp39-abi3-win_amd64.whl (18.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_x86_64.whl (31.2 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ x86-64

tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_aarch64.whl (31.4 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

tree_sitter_gram-0.3.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (29.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

tree_sitter_gram-0.3.3-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_gram-0.3.3-cp39-abi3-macosx_11_0_arm64.whl (15.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

tree_sitter_gram-0.3.3-cp39-abi3-macosx_10_9_x86_64.whl (15.5 kB view details)

Uploaded CPython 3.9+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_gram-0.3.3.tar.gz.

File metadata

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

File hashes

Hashes for tree_sitter_gram-0.3.3.tar.gz
Algorithm Hash digest
SHA256 227151831bc03fc00eaf3276f49020472fae6ed33e3ae92e86928bacbfa31f7e
MD5 7dd42d574c48c7785c06df5e0887a1d8
BLAKE2b-256 9e9c5118e808a46cd68dfe0b11014f5eb10a58901608548dd22e8390c12de831

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 17b7842b078bba9a40929aa113cb9818546e9360b3cc1520a8ee3d2e5d31e595
MD5 b067a07f257809b359f78df3c66b6e30
BLAKE2b-256 810e287649fb910542fda111b09e01f04b60f0bc1f0572658dc16e59f8d94307

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 acaff6102f82b32d1ec8981df7eef415b5531d45699de1b0aeaaebf7e8be9453
MD5 ca95b6e4885ba0443bd39215a65d4b2d
BLAKE2b-256 f9f91201ad46bee2193e79d9b32581c57c438c9aeb8ef5425499d341ef598d1b

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5b87e480907aa607bb8e6ad911b0865a032524a767c772ff830114b6f017294e
MD5 62343ec779db28edc895f41448778341
BLAKE2b-256 2417c01078cb550910ac0100d8d9f5f893e15df836b7a74796c274c4e4038d11

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 9dddaa0cfcf6d72b3e297add6b44578f38403e00c8828c615316dcf310f33f42
MD5 4b24a6a052c89e1f290c9381ad02736c
BLAKE2b-256 6ee68120ce5bb2c1d1739551eb326a875c3db66d16558956fa86da33ca121b36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5147c05984c64d7e9851435dd6e744b0e90a130bc9f1b7af89da9a17df1d88d5
MD5 38cff82919115ba1b015ce5ab61c04a1
BLAKE2b-256 6e977f0e9f36c01c0037595140e29569d47ea657a5c263d79e3e2464dbcfa26c

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.3.3-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 afbc9a7adc8000f753ae5d11ad17fa7f556a2eaca0459b6ca4ed3e0d31a4a4b5
MD5 04782da14807603837dc13aebe8135b2
BLAKE2b-256 1705ea40666eb1a8b605a8b584f5ef3a325513f7555288e93b4dc97000b6566c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e28868e97a15095112f824142a739c0acc94dac1855f0187eda14eb42644f809
MD5 5e7dc8ec64bb9fc86b84653a9ce5fe38
BLAKE2b-256 8e64b01182d38653c3fb8f4866bae3a819052239306c0515dbef5de11a8bb2d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.3.3-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c5e64291cdf05a625f4030b873025488b27c1aaf9a86a85bc8d5c596c0f9f6c2
MD5 0ca80f264b20a4f612335628a3bae863
BLAKE2b-256 509cbe0bece9899dbc17eeaa60d0a88d897df7a26456cb2190562a9a343327ef

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