Skip to content
Playground(another site)

`tree-sitter-bynk`

The tree-sitter grammar for Bynk. It is the source of truth for structural tooling — syntax highlighting (the playground’s live editor, and any editor that speaks tree-sitter). The static documentation site highlights its code blocks separately, via Expressive Code / Shiki from the editor’s TextMate grammar.

PathWhat it is
grammar.jsThe grammar definition — the file you edit.
src/parser.c, src/scanner.cGenerated parser plus a hand-written external scanner (for --- … --- doc blocks and raw strings).
src/grammar.json, src/node-types.jsonGenerated grammar metadata.
queries/highlights.scmHighlight queries (the highlight groups).
queries/injections.scmLanguage-injection queries: a tagged multi-line string’s body ("""sql) as the tag’s language.
test/corpus/Versioned parse-tree test cases.

The generated files in src/ are committed. The book’s grammar reference is generated from src/grammar.json.

With the tree-sitter CLI:

Terminal window
npm install # once
npm run build # tree-sitter generate → regenerates src/
npm test # tree-sitter test → runs the corpus

After editing grammar.js, run npm run build to regenerate the parser, then npm test to check it against the corpus. A corpus case is a named section: the source, a --- separator, and the expected S-expression parse tree.

highlights.scm maps grammar nodes to standard highlight groups — @keyword (and @keyword.declaration, .import, .modifier, .operator), @type, @type.builtin, @string, @number, @comment, @function, @variable, @operator, @punctuation.*, and more. These groups drive the editor (VS Code via vscode-bynk) and the playground’s wasm tree-sitter highlighter, so interactive highlighting stays correct as the grammar evolves. The static documentation site highlights ```bynk blocks separately, via Expressive Code / Shiki from the editor’s TextMate grammar, so it is not driven by these tree-sitter highlight groups.

A multi-line string may carry a language tag, """sql or r"""regex. The tag is a string_tag node, and the body is a string_body (or, raw, raw_string_body) node; injections.scm injects the body as the language the tag names. Interpolation holes and escapes are children of the body, so they are left out of the injected text. An editor with no grammar for the tag shows a plain string.

grammar.js is regenerated to src/ via tree-sitter generate; commit the generated files together with the grammar change so downstream consumers (the editors and the playground’s highlighter) stay consistent.