summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 03:27:34 -0300
committerGabriel Schneider <[email protected]>2026-11-21 03:29:17 -0300
commitd04f4acfb9af968caaa53d6cf10a486622c95400 (patch)
tree37a788057c7f1b97d1e4d807e145e0389f39ae88
parentdea2920233bbb64b20f7ccebd42ac5beab14033d (diff)
downloadpardes-d04f4acfb9af968caaa53d6cf10a486622c95400.tar.gz
pardes-d04f4acfb9af968caaa53d6cf10a486622c95400.zip
docs: the library as a dependent package and a browser take it (docs/typ/building.typ, As a library): the options `.grammars`, `.languages` and `.editor`, the configure error Zig would not give, `grammar_manifest` read at configure time, `wasmModule` one call a language; The patch view: `formatPatch`, its `PatchCtx` and each field's default, a `PatchRow`'s fields and kinds, a reader's two blobs; In a browser: the module's exports, `patch`'s 20-byte header and 36-byte record byte by byte (u32, little-endian, 0 for no line number), the three WASI imports a language's module has and the none of the patch view's; the consumer-test line; `zig build book` renders it (132/132 steps) and core-test's docs check passes (9/9)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--docs/typ/building.typ111
1 files changed, 106 insertions, 5 deletions
diff --git a/docs/typ/building.typ b/docs/typ/building.typ
index 94939452..f2b3289f 100644
--- a/docs/typ/building.typ
+++ b/docs/typ/building.typ
@@ -122,18 +122,38 @@ exe.root_module.addImport("pardes-editor", pardes.module("pardes-editor"));
`.grammars`: the tree-sitter grammars compiled in: `none` (the runtime
alone), `minimal` (C, C++ and Zig) or `full` (all of them; the default).
-`.editor`: exports `pardes-editor` besides `pardes-syntax`, and with it
-fetches uucode, mvzr and vaxis.
+`.languages`: instead of `.grammars`, the languages compiled in by name
+(`"rust"`, or `&.{ "rust", "go" }`), each with what it needs (markdown
+its inline grammar); a name the manifest does not have fails the
+configure. `.editor`: exports `pardes-editor` besides `pardes-syntax`,
+and with it fetches uucode, mvzr and vaxis.
+
+The manifest, for a package's build script to read at configure time
+(`@import("pardes").grammar_manifest.all`: each grammar's name, its
+extensions and what it needs), is `grammar_manifest`.
+
+A browser's module, one call a language (`wasmModule`, below):
+
+```
+const pardes = @import("pardes");
+b.installArtifact(pardes.wasmModule(b, .{ .language = "rust" }));
+b.installArtifact(pardes.wasmModule(b, .{})); // the patch view alone
+```
Every dependency but tree-sitter's runtime is lazy in the manifest, so
such a package fetches what it asked for and nothing else.
`pardes-editor` has `pardes-syntax` in it as `.syntax`: a file belongs
to one module, so a package imports one of the two. `test/consumer` is
-such a package, with both shapes; `consumer-test`, which `unit-test` runs,
+such a package, with every shape; `consumer-test`, which `unit-test` runs,
builds and runs it.
`build.zig.zon` names pardes by its path: `.pardes = .{ .path = "../pardes" }`.
+Zig reports an option a dependency does not have, or a value it cannot
+read, and builds on with the default (exit code 0): pardes ends the
+configure itself (exit code 1, the manifest's names) for a language it
+does not have, and for `.grammars` given beside `.languages`.
+
=== The syntax
It is the editor's own code under the names it has there. A language is
@@ -146,6 +166,7 @@ for a language's name.
[`theme`, `themes`, `page`, `ink`, `synInk`], [a theme by name and what it draws a page, its text and each class in],
[`lineCount`, `lineStartOffset`, `lineSlice`], [a line's bytes from its number],
[`grammars`, `supportsPath`, `pathFor`], [every grammar, and whether this build has a path's],
+ [`formatPatch`, `PatchCtx`, `Patch`, `PatchRow`, `PatchSource`], [a unified diff stacked as the patch view shows it (below)],
[`start`, `stop`], [tree-sitter's allocator, and the end of the parsers kept per language],
)
@@ -156,6 +177,85 @@ pardes's `zig-pkg` shares the one copy. What a pane measures stays out: a
cell's width is vaxis's and uucode's, and a tab is `config.tab_width`
cells wherever it stands.
+=== The patch view
+
+`formatPatch` stacks a unified diff as pardes's +Diff shows it, with
+nothing of the editor: each hunk under its `path:line`, what it stands in
+above it, its lines behind their markers on their grounds, and the words a
+changed line changed emphasised (delta's way). It returns a `Patch`, its
+text and a `PatchRow` for each of its lines (row _i_ is line _i_), all in
+the arena it is handed:
+
+#pairs(
+ [`kind`], [`other` (a mailed patch's headers, message, diffstat), `meta` (a section's own words: a mode, a rename, `Binary files ... differ`), `hunk` (its label, a star a declaration it stands in), `declaration` (what it stands in: a declaration's `path:line` and header lines from the file, or git's own words after the `@@`), `context`, `added`, `removed`],
+ [`path`, `line`], [the file its section names, and the line of it the row points at (0 for none)],
+ [`old`, `new`], [a hunk line's numbers in the old and the new file, null on the side it is not on],
+ [`location_end`, `code_start`], [where a label's `path:line` ends and what follows it starts],
+ [`styles`], [a byte a byte of its text: a `Syn` in `syn_bits` (with colours), `ground_add` or `ground_del` on a changed line, `ground_line` on the marker of one no other line changed, `ground_emph` on a changed word],
+ [`no_newline`], [the diff's `\ No newline at end of file` follows it],
+)
+
+What it takes of the program is a `PatchCtx`: an `arena`, and, each with
+a default, `source` (the file a section names, as a `PatchSource`: its
+text and path; none by default, so each hunk is numbered by the diff and
+stands under git's words), `declarations` (none; `PatchCtx.parsed` reads
+them from the file's parse), `colors` (none; `PatchCtx.languages` colours
+each hunk as its file's language), `width` (code points; it decides
+whether two lines are one changed) and `tslocations`. With no `colors`
+and no `declarations` it calls nothing of tree-sitter. A reader with a
+commit's two blobs hands the new one in as `source` (or the old one, for a
+file the commit deleted): the hunk is found in it on either side.
+
+=== In a browser
+
+`wasmModule(b, .{ .language = "rust" })`, called from a package's build
+script after `@import("pardes")` (its dependency named `pardes`), gives
+the compile step of one module for a browser: wasm32-wasi, a reactor (no
+`main`: `_initialize`, then any export), with that language's grammar and
+what it needs, tree-sitter's runtime and pardes's highlighter. With no
+`.language` it is the patch view alone, with no tree-sitter in it and no
+import at all. `.optimize` is `ReleaseSmall` unless given. A name the
+manifest does not have fails the configure. The module is
+`pardes-<language>.wasm`, or `pardes-patch.wasm`; its exports
+(`core/lib_wasm.zig`) are the same in every module:
+
+#pairs(
+ [`memory`, `_initialize`], [its memory, and what a reactor runs once before any other call],
+ [`reserve(len)`, `release(ptr, len)`], [`len` bytes for the page to write an argument into (at least one, so `reserve(0)` is a pointer too), and their return],
+ [`highlight(path, path_len, text, len)`], [(a module with a language) a style byte for each byte of `text`: 0 none, 1 keyword, 2 string, 3 number, 4 comment, as pardes colours the file `path` names by its extension; all 0 for a path of another language. The module's until the next `highlight`],
+ [`patch(text, len)`], [the diff `text` stacked as the patch view shows it, with no file and no colours: a pointer to a header. The module's until the next `patch`],
+)
+
+Each returns 0 when its memory runs out. Pointers and lengths are
+wasm32's: unsigned 32-bit; in memory they are little-endian. `patch`'s
+header is five u32, 20 bytes:
+
+#pairs(
+ [0 `text`, 4 `text_len`], [the rows' text, a line a row, each ending in a newline; the rows' paths follow it in the same buffer],
+ [8 `styles`], [a byte for each byte of the text: `ground_add` 0x80 or `ground_del` 0x40 on a changed line, `ground_line` 0x10 on the marker of one no other line changed, `ground_emph` 0x20 on the words a changed line changed],
+ [12 `rows`, 16 `row_count`], [the rows, a record of nine u32 (36 bytes) each],
+)
+
+and a row's record:
+
+#pairs(
+ [0 `kind`], [0 other, 1 meta, 2 hunk, 3 declaration (git's words after the `@@`), 4 context, 5 added, 6 removed],
+ [4 `old`, 8 `new`], [its numbers in the old and the new file, from 1; 0 where it has none],
+ [12 `code_start`], [where its code starts in its text: after a hunk label's `path:line` and stars],
+ [16 `text_offset`, 20 `text_len`], [its text, without its newline, in the header's `text`],
+ [24 `path_offset`, 28 `path_len`], [its section's path, in the header's `text` too],
+ [32 `flags`], [bit 0: the diff has `\ No newline at end of file` after it],
+)
+
+A module with a language imports three functions of
+`wasi_snapshot_preview1`, `fd_write`, `fd_seek` and `fd_close` (libc's
+streams, which tree-sitter's debug output names; `fd_write` is also how a
+panic's message reaches stderr); a page stubs each (`fd_write` may write
+to the console, the others answer `ENOSYS`, 52). The patch view's module
+imports nothing. `test/consumer/wasm.mjs` is such a page, run by node:
+`consumer-test` builds both shapes through `wasmModule` and runs them when
+`node` is on PATH, and says so when it is not.
+
=== The editor
`pardes-editor` (`core/lib_editor.zig`) is the text pane as a library:
@@ -198,8 +298,9 @@ zig build kitty-harness kitty graphics through a pane end to end (a fake kitt
terminal outside on the tui, the GPU capture on the gui;
kitten icat and chafa too when installed)
zig build syntax deterministic per-byte highlighting snapshots
-zig build consumer-test the library, from a package that depends on pardes (test/consumer);
- unit-test runs it too
+zig build consumer-test the library, from a package that depends on pardes (test/consumer):
+ its shapes, a language named alone, the browser's modules
+ under node; unit-test runs it too
zig build hxlib helix's cases on the library's editor (-- --parity: against the file pane)
zig build behaviour-test behaviour through the 9P tree, in process (test/behaviour/),
and the T1 runner's short run of random 9P requests