- JavaScript 54.4%
- C 33%
- Tree-sitter Query 12.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
CI / Grammar, queries & corpus (push) Successful in 16s
Reviewed-on: #2 |
||
| .forgejo/workflows | ||
| queries | ||
| scripts | ||
| src | ||
| test | ||
| .gitattributes | ||
| .gitignore | ||
| grammar.js | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tree-sitter.json | ||
tree-sitter-gram
A tree-sitter grammar for Gram, the open-source recipe DSL.
Website · Documentation · Editors guide
Note
Primary development happens on Forgejo, with read-only automatic mirrors on GitHub and Codeberg. Issues and pull requests are handled on Forgejo.
This 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 grammar reads the same text the same way, including its tolerance. What is not an element is prose, never an error.
v0.1.x reads Gram 1.5–1.6 syntax.
Editor support
Queries are shipped for Neovim, Helix, and Zed (via zed-gram). See the editors guide for setup instructions in each editor.
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 forgrammar.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