tree-sitter-gren
March 31, 2026 · View on GitHub
tree-sitter-gren
A tree-sitter grammar for the Gren programming language.
Prerequisites
- Node.js (v14+)
- tree-sitter CLI (
npm install -g tree-sitter-cliorcargo install tree-sitter-cli) - A C compiler (gcc, clang, or MSVC)
Building
Install dependencies and generate the parser:
npm install
npm run build
This runs tree-sitter generate, which reads grammar.js and produces the C parser in src/parser.c.
Testing
Run the test suite:
npm test
Or build and test in one step:
npm run test:dev
Updating test expectations
After changing the grammar, use npm run test:update to regenerate the expected parse trees:
npm run test:update
Parsing a file
tree-sitter parse path/to/file.gren
Project Structure
grammar.js Main grammar definition
src/scanner.c External scanner (indentation)
src/parser.c Generated parser (do not edit)
queries/
highlights.scm Syntax highlighting queries
locals.scm Local scope queries
tags.scm Symbol tagging queries
injections.scm Language injection queries
test/corpus/ Test corpus files
bindings/ Language bindings (Node, Rust, Swift)
Editing the Grammar
- Modify
grammar.js(andsrc/scanner.cif changing lexer behavior) - Run
npm run test:devto regenerate and test - Verify against real
.grenfiles withtree-sitter parse
Editor Integration
The generated src/parser.c is the universal artifact. How it gets compiled and loaded depends on the editor.
VS Code
VS Code extensions load the parser as a WebAssembly module. Build it with:
npx tree-sitter build --wasm
This produces tree-sitter-gren.wasm, a self-contained binary with the parser tables and scanner. A VS Code extension loads this at runtime via tree-sitter's WASM bindings.
Note: On Apple Silicon (arm64) you may see a warning like
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8). This is safe to ignore — the WASM file is still built correctly.
The recommended VS Code extension is tree-sitter-vscode by AlecGhost. It ships no built-in parsers — you provide your own WASM file and query files.
Step 1: Configure the extension
Open VS Code settings: User Settings > Extensions > tree-sitter-vscode > click the "Edit in settings.json" link. Add the following to your settings.json:
"tree-sitter-vscode.languageConfigs": [
{
"lang": "gren",
"parser": "/path/to/tree-sitter-gren/tree-sitter-gren.wasm",
"highlights": "/path/to/tree-sitter-gren/queries/highlights.scm",
"injections": "/path/to/tree-sitter-gren/queries/injections.scm"
}
]
Replace /path/to/tree-sitter-gren with the absolute path to this repository.
Step 2: Register the .gren file type
The extension doesn't know about .gren files by default. You need to register the file type in the extension's own package.json:
- Open the Command Palette (
Cmd+Pon macOS,Ctrl+Pon Linux/Windows) - Run "Extensions: Open Extensions Folder"
- Open
alecghost.tree-sitter-vscode-<version>/package.json - Under the
"contributes"object, add:
"languages": [
{
"id": "gren",
"extensions": [
".gren"
]
}
]
Step 3: Reload
Run the "tree-sitter-vscode: Reload" command from the Command Palette to apply the changes.
Neovim
Neovim's nvim-treesitter compiles src/parser.c and src/scanner.c into a shared library on the user's machine. Register the grammar by adding it to your nvim-treesitter config:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.gren = {
install_info = {
url = "path/to/tree-sitter-gren",
files = { "src/parser.c", "src/scanner.c" },
},
filetype = "gren",
}
Then run :TSInstall gren.
Zed
This repository includes a Zed extension at editors/zed/ with syntax highlighting, indentation, brackets, and outline support. Zed clones the grammar source directly from the repository URL specified in extension.toml.
Install as a dev extension:
- Open Zed
- Open the Command Palette (
Cmd+Shift+Pon macOS) - Run "zed: install dev extension"
- Select the
editors/zed/directory from this repository
Extension structure:
editors/zed/
extension.toml Extension manifest (points Zed at the grammar repo)
languages/gren/
config.toml Language config (file type, comments, brackets)
highlights.scm Syntax highlighting queries
indents.scm Auto-indent rules
brackets.scm Bracket matching
outline.scm Symbol outline
Helix
Helix has built-in support for Gren. No additional configuration is needed.
Bindings
Rust
Add to your Cargo.toml:
[dependencies]
tree-sitter-gren = { path = "path/to/tree-sitter-gren" }
The parser.c and scanner.c files are compiled by cc via build.rs and statically linked into your binary.
Node.js
const Parser = require("tree-sitter");
const Gren = require("tree-sitter-gren");
const parser = new Parser();
parser.setLanguage(Gren);
const tree = parser.parse('module Main exposing (..)');
console.log(tree.rootNode.toString());
Thanks
Shamelessly stolen from the tree-sitter-elm project.
Want to help?
Help writing some tests or simply find valid gren files that fail parsing. Tests are located in the test folder and separated in parser tests and highlighting tests.
License
MIT