Expand description
Bynk v0.3 compiler library.
Compiles .bynk commons source into TypeScript modules.
Pipeline: lex → parse → resolve → check → emit.
v0.3 introduces multi-file commons and the uses mechanism. A “project”
is a directory containing one or more commons; a commons is either a
single .bynk file or a directory of .bynk files that share a
commons name header. See compile_project.
The single-string entrypoint compile remains for v0–v0.2 fixtures
and any single-file commons that does not declare uses against another
commons.
Re-exports§
pub use bynk_fmt as fmt;
Modules§
- actors
- v0.45 actor contracts (the actors-foundations slice).
- ast
- Abstract syntax tree types for Bynk v0 (spec §9.2).
- builtin_
names - Centralised string literals for the language’s built-in vocabulary (refactor track item 8, v0.29.11). Built-in type/method names were compared as bare string literals scattered across the checker, emitter, and project modules; a typo was a silent never-match. One edit point per name now.
- checker
- Type checker and refinement validator (spec §§5–6, v0.1 §4.2, v0.2 §4.2).
- cli
- The
bynkccommand-line interface definition. - diagnostics
- Central registry of diagnostic codes.
- emitter
- TypeScript emission (spec §7, v0.1 §6, v0.2 §6).
- error
- Compiler diagnostics.
- expr_
types - v0.30.2 (ADR 0063): the expression-type sink.
- firstparty
- First-party standard adapters embedded in the toolchain (v0.17 §4.2).
- hints
- v0.27 (ADR 0056): the inlay-hint sink.
- index
- v0.25: the project-wide binding index (ADR 0053).
- kernel_
methods - v0.30.2 (ADR 0063): the enumerable kernel-method registry.
- keywords
- Registry of reserved keywords.
- lexer
- Lexer for Bynk v0.
- locals
- v0.31 (ADR 0064): the local-binding sink.
- parser
- Hand-written recursive-descent parser for Bynk v0.
- project
- Multi-file project compilation (v0.3 §3.2 and §3.3, v0.4 §3.5).
- requirements
- v0.99 (ADR — agent capability provenance): the capability-requirement ledger.
- resolver
- Name resolution (spec §5.1, v0.1 §4.1, v0.2 §4.1).
- span
- Source position spans.
- test_
json - v0.59: the
bynkc test --format jsonresult model, plus the parser that folds the runner’s NDJSON event stream into it.
Structs§
- Attributed
Error - v0.24 (ADR 0052): a compile error attributed — where possible — to the
project-relative source file it belongs to, tagged at the collection
point (the phase that produced it knows which file it was processing).
Noneis the project-level bucket: validations spanning files (group/cycle/directory consistency) with no single owning file. - Compile
Error - A compile error.
- Compile
Options - Options for
compile_project. Construct withCompileOptions::singleorCompileOptions::split, then chain.target(…)/.platform(…)/.import_ext(…)to override the bundle/default-platform/.jsdefaults. - Compiled
- v0.89 (ADR 0117): single-file compile that also returns the non-failing
warnings produced on success — what the CLI prints.
compileis the warning-discarding convenience over this. - Compiled
File - One generated TypeScript file.
- Diagnostic
- One diagnostic produced from a recovery-mode compile of a single file.
- Discovered
Case - One discovered
test "<name>"case.locationpoints at the case-name literal (a run failure instead points at the failingassert), giving the editor click-through to the declaration before any run. - Discovered
Suite - v0.67: a discovered test suite — one
test <target>group (unit) ortest integration "<suite>"(integration).name+kindmirror exactly what the NDJSON runner emits atsuite-begin(kind"unit"carries the joined target name;"integration"carries the bare suite name), so the editor reconciles discovery and run documents to the same tree items. - File
Diagnostics - Per-file diagnostics from a whole-project analysis.
v0.24 (ADR 0052):
textis the analysed snapshot — positions must convert against it, not a newer buffer (the analyse→publish window is real). - Project
Diagnostics - v0.24: the result of
diagnose_project. Every discovered file appears infiles— clean files with an empty list — so a consumer can clear stale diagnostics.unattributedholds project-level diagnostics with no single owning file (group/cycle/directory validations). - Project
Failure - v0.24: a failed build with its attribution and snapshots intact — what
the CLI renders rich (ariadne source context per file); the plain
compile_project*wrappers flatten it to the pre-v0.24 error list. - Project
Output - Result of compiling a project.
- Project
Paths - v0.113 (DECISION S): the project’s source tree, read from
bynk.toml’s[paths]section. Test-ness is a property of thesuitedeclaration, not of a directory, so the layout is a flatincludelist of trees to compile and anexcludelist of subtrees to skip — not the role-namedsrc/testssplit. Eachincludeentry is a root walked for.bynkfiles; a file’s identity path is relative to theincluderoot that contains it. - Strip
Error - A failure to strip TypeScript to JavaScript. For input produced by the Bynk
emitter this should never occur — the emitter only emits valid, strip-only
TypeScript (ADR 0136) — so a
StripErrorindicates an emitter or toolchain bug rather than user error. - Test
Location - A project-root-relative
path:line:colsource location, structured. Line and col are 1-indexed (thebynk_syntax::span::line_colconvention).
Enums§
- Build
Target - The build target. Determines how cross-context calls and per-context modules are emitted (v0.8). Bundle mode is the default — all contexts emit into one TypeScript bundle and cross-context calls are direct function invocations. Workers mode produces per-context Cloudflare Worker bundles that communicate via Service Bindings.
- Import
Ext - The extension emitted import specifiers use (
import … from "./x.<ext>"). - Platform
- The deploy platform — a selection axis distinct from the
--target {bundle,workers}emit mode (§6.2). It chooses whichbynk-<platform>.tsbinding is linked for thebynksurface. v0.17 shippedcloudflare; v0.18 addsnode, making the axis observable (and giving v0.19’s platform-lock enforcement a second platform to fire against). - Roots
- Where a project’s
.bynkfiles live. - Severity
- Severity classification for a
CompileError. Mirrors LSP severity levels so the LSP server can map diagnostics to the protocol without reinterpreting error categories. Lives in the syntax leaf besideCompileError(it classifies one): shared by the IDE diagnose path (bynk-ide) and theshort/jsonrenderers, without either depending on the other.
Constants§
- NODE_
MAJOR_ FLOOR - Minimum supported Node.js major version for the
nodeplatform binding and for running Bynk’s emitted TypeScript.
Functions§
- compile
- Compile a single Bynk source string to a TypeScript string.
- compile_
project - Compile a Bynk project, keeping error attribution + snapshots on failure
(so the CLI can render project errors with source context, ADR 0052). Use
.map_err(ProjectFailure::flatten)for the flattenedVec<CompileError>shape. - compile_
with_ warnings - diagnose
- Best-effort single-file compilation that always returns diagnostics.
- diagnose_
project - v0.24 (ADR 0052): non-bailing, overlay-aware, file-attributed project
diagnostics — the LSP analysis entry point, distinct from
compile_project(which bails and emits).overlaymaps canonicalised absolute paths to buffer text layered over disk reads. - print_
errors - Render to stderr with color, used by the CLI.
- print_
errors_ short - v0.38 (ADR 0071): one terse line per diagnostic for tooling consumers
(
bynkc check --format short):path:line:col: <severity>[<category>]: <message>. Line/column are 1-indexed, computed from the byte span against the source. The VS Codebynkcproblem-matcher keys off this exact shape — keep it stable. - print_
project_ errors - Render project-level errors as plain
[category] messagelines — the fallback for errors with no file attribution. Rich, source-context rendering lives in the front-end’s project-failure renderer (v0.24). - print_
project_ failure - v0.24 (ADR 0052 rider): render a failed project build with full ariadne source context per file — the attribution built for the LSP, fixing the standing gap where project-mode CLI errors were bare lines while single-file mode had rich rendering. Unattributed (project-level) errors keep the plain form.
- print_
project_ failure_ short - The project-failure analogue of
bynk_render::print_errors_short: each attributed error is positioned against its file’s snapshot; an unattributed (project-level) error falls back to<severity>[<category>]: <message>. - print_
project_ warnings - v0.89 (ADR 0117): print a successful build’s non-failing warnings. A
successful build keeps no per-file snapshots, so warnings render in the
plain
warning[<category>]: <message>form (with the owning file, when known) rather than ariadne source context. - project_
failure_ short_ lines - The string form of
print_project_failure_short: onepath:line:col: severity[category]: messageline per attributed error (an unattributed project-level error falls back toseverity[category]: message). Backs both the printer above and thebynkc test --format jsoncompile-error document, whosediagnosticsthe VS Codebynkcproblem-matcher re-parses. - read_
project_ paths - v0.113: read
bynk.tomlfromproject_root. Returns the conventional layout (seeProjectPaths::conventional) if the file is missing or declares no[paths] include. Honoursinclude/excludeunder[paths], each an array of path strings; anything else is ignored. A minimal hand-rolled TOML reader — we only need string and string-array values here. - render_
errors - Render a list of compile errors to a string (for tests) using the given filename as the diagnostic source label.
- render_
errors_ plain - Render a list of compile errors to a string with colour disabled and the
given filename as the source label. Unlike
render_errors, the output contains no ANSI escape codes, so it is byte-stable — suitable for the committed diagnostic transcripts undersite/src/diagnostics/. - render_
errors_ short - The string form of
print_errors_short— one…[category]: messageline per error, each newline-terminated. The renderer behind the CLI’s--format short, exposed for testing. - render_
project_ errors - Render a list of compile errors as plain
[category] messagelines (with notes), for test assertion. - strip_
project_ to_ js - Rewrite a compiled
ProjectOutputfrom TypeScript into a JavaScript artefact (the in-browser track’s first-class JS output — ADR 0137). The emitter always produces TypeScript; a JS artefact is that same output with types stripped, which is total because the emitter is strip-only (ADR 0136). - strip_
types - Strip TypeScript types from
source, returning equivalent JavaScript. - write_
compiled_ file - Write a single
CompiledFileunderdir, map-aware: a.bynk-sourced file gets a sibling.ts.mapand a//# sourceMappingURLtrailer (slice 1, ADR 0103); a file with no map is written verbatim. Shared bywrite_outputandbynkc test’s output loops, so every disk-writing path emits maps uniformly (slice 2 —bynkc test --inspectruns the emitted.tsdirectly and needs the maps on disk). The trailer lives only on the on-disk artefact; the in-memoryfile.typescriptstays trailer-free, so golden comparisons are unaffected. The map name appends.mapto the output file name. - write_
output - Write a
ProjectOutput’s files underdir, creating parent directories as needed. The shared writer behind bothbynkc’scompile/testpaths andbynk dev’s in-process build (slice 7) — so the on-disk result is identical however the build was driven.