GDL/IDL grammar for tree-sitter
Project description
tree-sitter-gdl
GDL/IDL grammar for tree-sitter.
Parses .pro files written in GDL (GNU Data Language) / IDL (Interactive Data Language), used extensively in fusion research, astronomy, and earth science.
Installation
Python
uv add tree-sitter-gdl
Or with pip:
pip install tree-sitter-gdl
Usage
import tree_sitter_gdl
from tree_sitter import Parser
parser = Parser(tree_sitter_gdl.language())
code = b"""
pro analyze_data, shot, verbose=verbose
mds$open, 'experiment', shot
signal = mds$value('\\diagnostics::channel_01')
if n_elements(signal) gt 0 then begin
result = total(signal) / n_elements(signal)
endif
mds$close
end
"""
tree = parser.parse(code)
print(tree.root_node.type) # "source_file"
Node.js
npm install tree-sitter-gdl
const Parser = require("tree-sitter");
const GDL = require("tree-sitter-gdl");
const parser = new Parser();
parser.setLanguage(GDL);
const tree = parser.parse("pro hello\n print, 'world'\nend");
Supported Syntax
| Feature | Status |
|---|---|
Procedures (pro...end) |
✅ |
Functions (function...end) |
✅ |
| If/then/else (inline and block) | ✅ |
| For/foreach/while/repeat loops | ✅ |
| Case/switch statements | ✅ |
| Function/procedure calls | ✅ |
Keyword arguments (name=value, /flag) |
✅ |
Array subscripting (arr[i], arr[0:10:2]) |
✅ |
Structures ({tag: value}) |
✅ |
Member access (struct.member) |
✅ |
Object methods (obj->method()) |
✅ |
Word operators (eq, ne, lt, gt, and, or) |
✅ |
System variables (!pi, !error_state) |
✅ |
Line continuation ($) |
✅ |
Comments (;) |
✅ |
Ternary (cond ? a : b) |
✅ |
Matrix operators (#, ##) |
✅ |
| Common blocks | ✅ |
| Goto/labels | ✅ |
Batch include (@file) |
✅ |
MDSplus calls (mds$open, mds$value) |
✅ |
Development
Prerequisites
- Node.js 20+
- tree-sitter CLI (
npm install tree-sitter-cli@0.24.7) - Python 3.10+ (for Python bindings)
- C compiler (gcc, clang, or MSVC)
Build
# Generate parser from grammar
npx tree-sitter generate
# Run corpus tests
npx tree-sitter test
# Build and install Python bindings (editable)
uv pip install -e .
# Run Python tests
uv run pytest tests/ -v
Testing
# Run all tree-sitter corpus tests
npx tree-sitter test
# Parse a file
npx tree-sitter parse example.pro
# Run Python tests
uv run pytest tests/ -v
Versioning
Versions are derived automatically from git tags using setuptools-scm.
To release a new version:
# Tag on your fork
git tag v0.1.0
git push origin v0.1.0
# Push tag to upstream to trigger the release workflow
git push upstream v0.1.0
The release workflow builds wheels via cibuildwheel and publishes to PyPI
using trusted publishing (OIDC).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tree_sitter_gdl-0.1.1.dev0.tar.gz.
File metadata
- Download URL: tree_sitter_gdl-0.1.1.dev0.tar.gz
- Upload date:
- Size: 73.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b159d5e0c699deb4b73ac93f06158404bbb633f27f21a60c487a898a17fb903f
|
|
| MD5 |
94233cafbd47450ab03fc9ed7dcf4c89
|
|
| BLAKE2b-256 |
ec419161fedb735ebe98273324250bdbc94fd0f5dd3f8dc801cb368164162d42
|
Provenance
The following attestation bundles were made for tree_sitter_gdl-0.1.1.dev0.tar.gz:
Publisher:
release.yml on iterorganization/tree-sitter-gdl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_gdl-0.1.1.dev0.tar.gz -
Subject digest:
b159d5e0c699deb4b73ac93f06158404bbb633f27f21a60c487a898a17fb903f - Sigstore transparency entry: 1041892458
- Sigstore integration time:
-
Permalink:
iterorganization/tree-sitter-gdl@e2637e7f10926a3d91f467df90abec908cfb76a5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/iterorganization
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e2637e7f10926a3d91f467df90abec908cfb76a5 -
Trigger Event:
push
-
Statement type: