GLSL grammar for tree-sitter
Project description
tree-sitter-glsl
A specification-compliant GLSL and ESSL parser for tree-sitter covering the full GLSL 4.60 core grammar, all current Khronos extensions, and common real-world macro patterns.
Features
- Full GLSL 4.60 and ESSL 3.20 grammar
- All Khronos extension keywords, types, built-in functions, and variables
- Structured preprocessor parsing (
#define,#if/#ifdef/#elif/#else) - Macro expansion support for real-world shaders (
COMPAT_PRECISION,MYTYPE(args)) - Multilingual header support (
#ifdef __cpluspluslanguage injection) - Extension-defined grammar rules (
demote,terminateInvocation)
Queries
| File | Purpose |
|---|---|
highlights.scm |
Syntax highlighting with built-in function/variable/constant recognition |
injections.scm |
Language injection for #ifdef __cplusplus / __STDC__ guards |
locals.scm |
Scope-aware local variable tracking |
tags.scm |
Symbol indexing for code navigation |
| - | - |
version-tags.scm |
#version-dependent construct validation |
constructor-heuristics.scm |
Opt-in heuristic for capitalized constructor calls |
version-tags.scm and constructor-heuristics.scm are custom selectors,
that might be useful in some cases, but you likely don't need them.
Usage
Node.js
const Parser = require('tree-sitter');
const GLSL = require('tree-sitter-glsl-spec');
const parser = new Parser();
parser.setLanguage(GLSL);
const tree = parser.parse('void main() { gl_FragColor = vec4(1.0); }');
Rust
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_glsl_spec::LANGUAGE.into()).unwrap();
let tree = parser.parse("void main() { gl_FragColor = vec4(1.0); }", None).unwrap();
Python
import tree_sitter_glsl_spec as glsl
from tree_sitter import Parser
parser = Parser(glsl.language())
tree = parser.parse(b"void main() { gl_FragColor = vec4(1.0); }")
Development
npm install # Install dependencies
npx tree-sitter generate # Regenerate parser from grammar.js
npx tree-sitter test # Run corpus tests
npx eslint # Lint
npx tsc --noEmit # Type check
node scripts/audit_node_types.js --coverage # Grammar coverage analysis
The specification is included as a git submodule.
Run git submodule update --init to fetch it for spec-scraping scripts.
References
- Specification Document: Khronos - The OpenGL Shading Language, Version 4.60
- Specification Repository (BNF): GitHub - KhronosGroup/GLSL
Background
This project began as a fork of tree-sitter-glsl by Stephan Seitz, which inherited its grammar from tree-sitter-c. After running into too many quirks from the C grammar inheritance, I rewrote the grammar from scratch against the GLSL 4.60 specification.
Why not inherit from tree-sitter-c?
GLSL's syntax is C-like but substantially simpler. A dedicated grammar provides:
- Fewer ambiguities — 1 GLR conflict (without macros) vs C's 16. No pointers,
no K&R functions, no multi-word types, no
sizeof/typeof, no casts. - Flat expression trees — identifiers and literals appear directly in the tree
without the
unary_expression > postfix_expression > primary_expressionwrapper chain that a C-inherited grammar produces. - GLSL-native nodes — layout qualifiers with
name:/value:fields, precision qualifiers, interface blocks,demote/terminateInvocationextension statements. - Specification fidelity — every BNF production from the spec exists as a (hidden or visible) rule, documented with the original grammar notation.
License
This project is licensed under the MIT license.
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 Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_glsl_spec-1.0.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_glsl_spec-1.0.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 100.2 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a33b2499b30e43c6fca141daf621b174f5ec5f6d46b7c5d83029eed2ba34318f
|
|
| MD5 |
176b267aa6f9150cfc010d00b7b678bb
|
|
| BLAKE2b-256 |
db49d5d1b86029c56a6d4573013d077715227c67647c266a9e2e68766ae5d972
|
Provenance
The following attestation bundles were made for tree_sitter_glsl_spec-1.0.0-cp38-abi3-win_amd64.whl:
Publisher:
publish-pypi.yml on Caellian/tree-sitter-glsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_glsl_spec-1.0.0-cp38-abi3-win_amd64.whl -
Subject digest:
a33b2499b30e43c6fca141daf621b174f5ec5f6d46b7c5d83029eed2ba34318f - Sigstore transparency entry: 1247296559
- Sigstore integration time:
-
Permalink:
Caellian/tree-sitter-glsl@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Caellian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tree_sitter_glsl_spec-1.0.0-cp38-abi3-win32.whl.
File metadata
- Download URL: tree_sitter_glsl_spec-1.0.0-cp38-abi3-win32.whl
- Upload date:
- Size: 92.4 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea40b699843538901d85b8f41bb85794036e2a2eb76c470b8d0745d03151a9f4
|
|
| MD5 |
71f8f62b1741998b95a205ccbca1ba76
|
|
| BLAKE2b-256 |
739bac7489b6723ca4443d3dc7588d5501c7978499b380e06489d31b6dbb834f
|
Provenance
The following attestation bundles were made for tree_sitter_glsl_spec-1.0.0-cp38-abi3-win32.whl:
Publisher:
publish-pypi.yml on Caellian/tree-sitter-glsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_glsl_spec-1.0.0-cp38-abi3-win32.whl -
Subject digest:
ea40b699843538901d85b8f41bb85794036e2a2eb76c470b8d0745d03151a9f4 - Sigstore transparency entry: 1247296573
- Sigstore integration time:
-
Permalink:
Caellian/tree-sitter-glsl@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Caellian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tree_sitter_glsl_spec-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_glsl_spec-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 137.1 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24fef4cf8cf36225a45e28bd67d2c81988e62f6687517d52963c2daca4bd75cd
|
|
| MD5 |
eb97b9d205c02635e5bb1cb329fcadaa
|
|
| BLAKE2b-256 |
88dc5a5d38d9439a31f62adadfb138de51e6119c0a6bb4ff089b67b93b04befc
|
Provenance
The following attestation bundles were made for tree_sitter_glsl_spec-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl:
Publisher:
publish-pypi.yml on Caellian/tree-sitter-glsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_glsl_spec-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
24fef4cf8cf36225a45e28bd67d2c81988e62f6687517d52963c2daca4bd75cd - Sigstore transparency entry: 1247296548
- Sigstore integration time:
-
Permalink:
Caellian/tree-sitter-glsl@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Caellian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tree_sitter_glsl_spec-1.0.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_glsl_spec-1.0.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 137.1 kB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1b4a2fd9f509b531feb2d7f4a463924cecfb76153bff940743daa233139e690
|
|
| MD5 |
20b335bf6075ac4f6cc0c85ee080a04c
|
|
| BLAKE2b-256 |
0e8cdac15fcb68384a7a77406f10df5069ab92c4b6e33b8b6e55843ab3a52b5f
|
Provenance
The following attestation bundles were made for tree_sitter_glsl_spec-1.0.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:
Publisher:
publish-pypi.yml on Caellian/tree-sitter-glsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_glsl_spec-1.0.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
f1b4a2fd9f509b531feb2d7f4a463924cecfb76153bff940743daa233139e690 - Sigstore transparency entry: 1247296568
- Sigstore integration time:
-
Permalink:
Caellian/tree-sitter-glsl@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Caellian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tree_sitter_glsl_spec-1.0.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_glsl_spec-1.0.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 90.3 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9db41331bd0fed94df326583fc027b662410fee1d917767fe71f1db1fe493574
|
|
| MD5 |
94c8c00943c48eec0b3772f44e4184ec
|
|
| BLAKE2b-256 |
2659698d28e8b7b4d256e5fa70f87aef4329ee8b355e6b0171ccad654c2705ee
|
Provenance
The following attestation bundles were made for tree_sitter_glsl_spec-1.0.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on Caellian/tree-sitter-glsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_glsl_spec-1.0.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
9db41331bd0fed94df326583fc027b662410fee1d917767fe71f1db1fe493574 - Sigstore transparency entry: 1247296554
- Sigstore integration time:
-
Permalink:
Caellian/tree-sitter-glsl@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Caellian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3a00d49a88cb53eec519b49d8e234e77d916f8ac -
Trigger Event:
workflow_dispatch
-
Statement type: