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.2.7.tar.gz (18.6 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.2.7-cp39-abi3-win_arm64.whl (16.6 kB view details)

Uploaded CPython 3.9+Windows ARM64

tree_sitter_gram-0.2.7-cp39-abi3-win_amd64.whl (17.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

tree_sitter_gram-0.2.7-cp39-abi3-musllinux_1_2_x86_64.whl (27.9 kB view details)

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

tree_sitter_gram-0.2.7-cp39-abi3-musllinux_1_2_aarch64.whl (28.7 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

tree_sitter_gram-0.2.7-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (29.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_gram-0.2.7-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (28.1 kB view details)

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

tree_sitter_gram-0.2.7-cp39-abi3-macosx_11_0_arm64.whl (16.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

tree_sitter_gram-0.2.7-cp39-abi3-macosx_10_9_x86_64.whl (15.8 kB view details)

Uploaded CPython 3.9+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_gram-0.2.7.tar.gz
  • Upload date:
  • Size: 18.6 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.2.7.tar.gz
Algorithm Hash digest
SHA256 5182f98083e4ed102a7008d324c3cdaad6cd43fd9ec8a232616ef5ff903e07ad
MD5 5eb4f33bdfdda589d99479fddc75b59d
BLAKE2b-256 bd0113260a8be0801a7bcd22ae3e4fd6d43495824d5eba795657bfb84f0ec16f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 f1909bfdcbea0627350989ef53efe726d2990d67323ffed476309f184074cca7
MD5 3919f43580000975b7e3f76619490bfe
BLAKE2b-256 9435616cb5683c6fa619a53e078ddd75373612603597f91a380ecdfcd837eca6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a8f2446357b958679f60c962c9324b7c0a3bb2c61fe2a3cc5ae9c22f638baa25
MD5 4d2d12a9e85ef5582f784939a020ee3b
BLAKE2b-256 7cbffb02a2abb086780b0a797ebba2896673a948ffde45fa93be9b852a44cfe6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c1cf25f748993294165aa7d2c2877445ef071fbb36b13b2b997bc49a1f60e5b
MD5 4316d06ca400e4e5b4a1273a67d82a1a
BLAKE2b-256 95a728562c1c8bf4407cf21e47c3e04927931ea8796607a74e806098c294cf4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d14898a2c644d1bd72c13538aeb182ee4c057d86d7b4c829f6aa556f519bfc6e
MD5 46bbb9fac844865d3aa10445e8b80397
BLAKE2b-256 9151a502c199b2420e311a001a32b87652d08a9077a89166dd432f7d9a3a1a20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 59c8540926bcd49d9641e402ba802ab9488332d936ccbc1895e3a41563d93d49
MD5 606febe40b689de0c02ad49047c2ef4f
BLAKE2b-256 e3f30f734b5f5f375066c714d87dc2d96a9138264bf04a3d38618f7729c01dbf

See more details on using hashes here.

File details

Details for the file tree_sitter_gram-0.2.7-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.2.7-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ebb7e6f8a46c65377c53a5f71ff13da5a9db3a54eb2d3187466a951aadfea8c9
MD5 83f8a50fafee76bf15fa6d84afdf8761
BLAKE2b-256 4d96c41ec345def98459b1bf5f5a6f0f86113ef99b62a7986d7a9f0a9be310c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae80165989f78e853c75cdd1927e41bc430dc0c5768f5826c37aa16ce6879628
MD5 a73976237ecdcd3771542c8fbee2bf4a
BLAKE2b-256 d344ab1621e5fa2b7b060344143549dc44804de680964b3d29abc328e93f4fef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gram-0.2.7-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a529a16d9da61ce09c6c1bfdbc4c2257e81055b88648a116651855747bfbdf87
MD5 fec49e83c5001482c65a3f4ba7fd01f2
BLAKE2b-256 6d4894bc437b505554f4782407076f1b849965d21df6da5e31b0dab60943b036

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