Tree-sitter grammar and highlight queries for the Gram recipe language (.gram), used by Neovim, Helix, and Zed. https://gram-lang.org
  • JavaScript 54.4%
  • C 33%
  • Tree-sitter Query 12.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-29 10:25:53 +01:00
.forgejo/workflows ci: fail once the release a vendored @gram-lang/parser awaits is on npm 2026-11-29 10:13:02 +01:00
queries feat: color a temperature's name as a label and give Helix and Zed their own injections 2026-11-25 11:11:24 +01:00
scripts ci: fail once the release a vendored @gram-lang/parser awaits is on npm 2026-11-29 10:13:02 +01:00
src chore: pin the gram dev/1.6 parser and corpus, cover gram#303 and release 0.1.1 2026-11-28 14:39:27 +01:00
test chore: pin the gram dev/1.6 parser and corpus, cover gram#303 and release 0.1.1 2026-11-28 14:39:27 +01:00
vendor chore: pin the gram dev/1.6 parser and corpus, cover gram#303 and release 0.1.1 2026-11-28 14:39:27 +01:00
.gitattributes feat: add the surface grammar, external scanner and test corpus 2026-11-25 09:36:03 +01:00
.gitignore feat: check the monorepo conformance corpus for parse errors 2026-11-25 09:39:27 +01:00
grammar.js docs: describe Gram as a declarative recipe DSL 2026-11-25 09:58:42 +01:00
LICENSE feat: add the surface grammar, external scanner and test corpus 2026-11-25 09:36:03 +01:00
package-lock.json chore: pin the gram dev/1.6 parser and corpus, cover gram#303 and release 0.1.1 2026-11-28 14:39:27 +01:00
package.json ci: fail once the release a vendored @gram-lang/parser awaits is on npm 2026-11-29 10:13:02 +01:00
README.md ci: fail once the release a vendored @gram-lang/parser awaits is on npm 2026-11-29 10:13:02 +01:00
tree-sitter.json chore: pin the gram dev/1.6 parser and corpus, cover gram#303 and release 0.1.1 2026-11-28 14:39:27 +01:00

tree-sitter-gram

A tree-sitter grammar for Gram, the declarative recipe DSL.

It is a surface grammar, written for highlighting, folding and outlines in editors. The reference grammar is packages/parser/grammar.ohm in the Gram monorepo: this one reads the same text the same way, including its tolerance. What is not an element is prose, never an error.

How it reads Gram

  • Gram is a PEG: a sigil (@, #, ~, ^, &, ={, ->&, <@, [, ##) only opens an element when what follows completes it. The external scanner (src/scanner.c, C99) looks ahead on the line to decide, and scans the names.
  • It reproduces grammar.ohm, it does not fix it. A name closed by braces runs over punctuation: @sel, puis ajouter l'eau{100 ml} is one ingredient, as the compiler reads it. A cut that looks wrong is a syntax question for grammar.ohm.
  • Line breaks carry meaning: a blank line ends a step, and ## only opens a section at the start of a block. Only spaces and tabs are skipped.

Development

tree-sitter generate   # src/parser.c is committed: editors build from src/ without the CLI
tree-sitter test       # test/corpus/

npm run conformance:fetch   # the monorepo's conformance corpus, at the ref pinned in package.json
npm run conformance         # every recipe of it parses with no ERROR or MISSING node
npm run oracle              # every recipe of it, and of test/corpus, is cut as @gram-lang/parser cuts it

The corpus is pinned in one place, package.json (gram.ref, a tag or a commit of the monorepo). GRAM_MONOREPO points the fetch to another clone, a local path included. The nine cases that are syntax errors in grammar.ohm are left out (gram.syntaxErrorCases); the other err-* cases are valid recipes and are checked.

The cutting oracle compares, recipe by recipe, the ranges of the elements read by @gram-lang/parser (a development dependency, pinned to the version of the corpus; between two Gram releases, a tarball packed from gram.ref in vendor/, awaiting the release named in gram.parserRelease: npm run parser:check, in CI on every push and weekly, fails once that release is on npm) with those of the tree-sitter nodes: ingredients, tools, timers, temperatures, target states, references, intermediate declarations, composite parents, anchors, imports and their bindings, section headers. A grammar that cuts @sel, puis ajouter l'eau{100 ml} into two ingredients fails it. Keep gram.ref and the @gram-lang/parser version in step.

Queries

The files under queries/ are generated by scripts/gen-queries.mjs from one table: each pattern has a role, and each role a capture name in Neovim, Helix and Zed, which name the same color differently (a section title is @markup.heading in Neovim, markup.heading in Helix, @title in Zed). The roles follow the scopes of the TextMate grammar (packages/parser/syntaxes/gram.tmLanguage.json in the monorepo), so a recipe has the same colors as in VS Code and Sublime. The script only accepts the capture names each editor documents.

File For
queries/highlights.scm Neovim (and tree-sitter highlight)
queries/injections.scm Neovim: the YAML of the frontmatter
queries/folds.scm Neovim: the frontmatter and each section
queries/helix/highlights.scm, injections.scm Helix
queries/zed/highlights.scm, injections.scm, outline.scm, brackets.scm Zed: colors, the YAML of the frontmatter, the outline of the sections by their title, matching brackets
npm run queries         # write queries/ from the table
npm run queries:check   # fail if queries/ is out of date or a query does not compile against the grammar
tree-sitter test        # also runs test/highlight/: colors asserted on Gram files, with queries/highlights.scm

Each editor's folder holds all its queries (injections.scm is the same in the three). Edit the table, never the generated files.

License

MIT