11 November 2026
A reference in our own style
Every name tabelline exports, on one page that looks like the rest of the site and that people and agents can link to. What Nim's doc tools give, why the page reads both them and the source, the choices behind it, the four rounds of review that shaped it, and how it is built.
tabelline had a guide, a book, specs and a feature map, and each of them tells a story: how
to make a table, how a gt example looks in Nim, what a verb must do. None of them answers the
plainest question a reader brings: what is fmtNumber, exactly, and what does it take? That is
the job of a reference: one place with every name, its signature and its doc comment. The
Reference is that place. This post tells how it was made.
What a reference is for
Two readers come to a reference. A person comes with a name: they saw colsLabel in an example
and want its arguments. An agent comes with a task: it needs the list of names, to find the one
that does the job, and a link it can give back. Both want the same things:
- every name, none missing, so the page can be trusted;
- the name's signature as the compiler sees it, and the doc comment as its author wrote it;
- a link that leads to the name and keeps working when the API grows;
- a way from tabelline's name to gt's and Great Tables', since most readers know one of them.
gt has a reference made by pkgdown, Great Tables one made by quartodoc: an index of every function, grouped by family, and a page for each. Nim has its own tools for this.
What Nim offers
Nim can write the documentation of a module in four ways, and the source is a fifth place to read. Each gives part of what a reference needs:
| Five places to read an API | ||
|---|---|---|
| what it gives | what it misses | |
nim doc | an HTML page per module, every exported name with its signature and doc comment | its own look, nimdoc's, not the site's; no links to gt |
nim jsondoc | the same as JSON: name, kind, signature, line | doc comments rendered as reStructuredText, where *, backticks and | mean something else; two of ours fail |
nim book | new in Nim 2.4 (#26139): a book from Markdown and a SUMMARY.md, in nimdoc's look | no module documentation of its own: it links to the pages of nim doc |
--project | nim doc --project: every module at once, with an index | Nim 2.2.4 stops with a RangeDefect on locales.nim, a constant of 150 000 characters (Nim 2.4.1 does not) |
| the source | doc comments as written (Markdown), the # ---- lines that cut a module in sections, imports and exports | the kinds and signatures as Nim prints them, after macros and templates |
So the page reads two of them. nim jsondoc, one module at a time, says which names a module
exports, of what kind, with what signature, on which line. The source, at that line, gives the
doc comment in the Markdown it was written in, and the section the name sits in. nim book
was the reason to look, and it is a good fit for a book of Markdown chapters, but a reference in
our own look needs the data, not someone else's HTML.
One page, from the simplest up
The page goes from the whole to the parts, the way this site explains things: the modules first, then each module, then each name. Every choice below is set against what gt and Great Tables do.
The modules
-
One page. Every name is on one page, so a reader searches it with the browser and an agent reads one file. gt: an index and a page per function. Great Tables: the same.
-
The modules come first, in one table. For each module: what it is, how many names it exports and of what kinds, the modules it exports again (
tabellineexports all of them,coreexportsstd/options), what it imports, which modules import it, what it uses from Nim. Each module's name in the table links to its section. gt: one package, no modules. Great Tables: modules exist but the reference groups by family. -
Dependency order. A module comes after every module it imports, so
coreis first andtabelline, which brings them all, is last. The table of contents has the same order, coloured by part. gt and Great Tables: by family, starting from the table itself (gt(),GT). -
How to read a signature. After the modules, a section says what the sugar of
tabella(data): bodyleaves out of a signature (the table a verb takes and returns), what the blocks and converters fill in, and what Nim's own words mean:sink, on every verb, and the few others, each with how many names use it. gt and Great Tables: R and Python signatures need no such note; Great Tables' methods takeself, which its reference leaves out.
The names of a module
- A table of names, by section. Under each module's heading and first sentence, a table lists
every name with its kind (
func ×9when it has nine overloads), grouped by the module's sections; each group links to its section. gt and Great Tables: the index lists names by family, with a one-line description. - The entries are folded. The names' entries sit in a fold that starts closed, so the page can be read as a map of modules. A link to a name inside a closed fold opens it.
One name
- A link that lasts.
api/#verbs-tabHeaderis the module and the name, and does not change when another module adds a name of the same spelling. The shortapi/#tabHeaderworks too, for the first name with that spelling. Operators are spelled by their character codes:#core-op26is&. The # beside a name is its link. gt:reference/tab_header.html. Great Tables:reference/GT.tab_header.html. - Signatures that fit a phone. Nim prints a signature wrapped at 80 columns; the page puts
one argument per line instead, as the guide writes a long call. The effects Nim inferred
(
raises,tags,gcsafe) are left out: they are in the source. - The doc comment as written. Read from the source, so its Markdown stays Markdown, and the names it mentions become links.
- Its counterparts, checked. A link to gt's and Great Tables' page for the same thing, only when that page exists: their reference indexes are read from their repositories, so no link leads to a 404. A name that is tabelline's own says Not from gt, as the feature map does.
- An example that runs. The shortest example in the specs that uses the name, folded, run while the page builds, with the table it makes. gt and Great Tables: examples run when their site is built, too.
The look
The page is written with blocks, not HTML, like every page of the site: two new blocks,
nbApi for a name's entry and nbFold for a fold, with their CSS in theme.nim. The page has
no HTML of its own, and the drift check passes.
On 11 November 2026 the page lists 356 names in 15 modules, and 232 have a doc comment.
tabHeader and tabStubhead are among those without one: the page says No doc comment yet,
which is a list of what to write.
Four rounds of review
The page was made on 10 November and reviewed four times on 11 November, on a phone, with the review mode. Each round asked for something a reference needs, and each answer is now on the page:
| From the request to the page | ||
|---|---|---|
| asked for | what it made | |
| ask | a reference from Nim's own tools, in our style | apidoc.nim (jsondoc and the source), the page, the block nbApi |
| 1 | every name linkable from outside; a table of the modules and their dependencies; Great Tables next to gt; a page in Learn tabelline; modules folded | anchors and the #, the modules table, references.nim, the Reference card, nbFold |
| 2 | a table of every name before each fold, grouped by section; what each module exports; the modules table grouped by module | the names tables, the exports row, the table turned so that it reads on a phone |
| 3 | the table of contents coloured by part; core first | pink, blue and green parts; the modules in dependency order |
| 4 | each module and each section linked from its table; the modules a module exports again; then how the sugar changes a signature, and what sink is | linked groups in both tables, the exports again row, the section Reading a signature |
What is still open
- Verbs as they are written. A verb's signature starts with
t: sink Tabella, which a reader never writes insidetabella(data): body. The page explains it once, in Reading a signature, with the other sugar and the words of Nim a signature uses (sink,lent,var,openArray,varargs,static); each verb's entry could still show the verb as it is called in a body. - The weight of the page. Every example table carries its own CSS, so the page is heavy. A change of its own, one table style per page, takes that away.
- Doc comments. A third of the names have none yet.
How it is built
The page reads four places, each with a small tool, and then is written like any other page.
1. nim jsondoc, one module at a time. tools/apidoc.nim runs it on each module a user
imports (the three modules that hold only CLDR data are left out), and keeps the JSON in
nimcache/apidoc/ under a hash of all of src/, so a build runs it only after a change. Each
entry gives a name, a kind, a signature and a line. Two fixes: jsondoc calls a func a proc, so
the kind is the signature's first word; and an operator's name comes quoted and HTML-escaped.
jsondoc: run once per change, cached 18 lines
proc jsondoc(module: string): JsonNode =
let src = root / "src" / module & ".nim"
let cache = root / "nimcache" / "apidoc"
# a module's JSON also depends on the modules it imports: key on the whole of src/
var h: Hash = 0
for f in walkDirRec(root / "src"):
if f.endsWith(".nim"): h = h !& hash(readFile(f))
let key = cache / module.replace("/", "_") & "-" & $(!$h).uint64 & ".json"
if not fileExists(key):
createDir(cache)
let tmp = cache / "out"
let (output, code) = execCmdEx("nim jsondoc --hints:off --warnings:off --outdir:" & quoteShell(tmp) &
" " & quoteShell(src), workingDir = root)
let made = tmp / module.lastPathPart & ".json"
if not fileExists(made):
quit "nim jsondoc failed on " & src & " (" & $code & "):\n" & output
moveFile(made, key)
parseJson(readFile(key))cleanSignature: the arguments, not the effects 21 lines
func cleanSignature(code: string): string =
## Nim's signature without the effects it inferred (`raises`, `tags`, `forbids`, `gcsafe`):
## a reader needs the arguments; the effects are in the source.
result = code
let a = result.find("{.")
if a < 0: return
let b = result.find(".}", a)
if b < 0: return
var kept: seq[string]
for p in result[a + 2 ..< b].split(", "):
let p = p.strip
if p.len == 0: continue
if p.startsWith("raises:") or p.startsWith("tags:") or p.startsWith("forbids:") or p in ["gcsafe", "noSideEffect"]:
continue
kept.add p
# a list inside a pragma (`raises: [A, B]`) was split too: only keep the pragma when no part of
# a list is left over
let rest = if kept.len == 0 or kept.anyIt(it.endsWith("]") or it.contains("[")): "" else: " {." & kept.join(", ") & ".}"
result = (result[0 ..< a].strip(leading = false) & rest).strip(leading = false)
# Nim wraps a long signature before the pragma: a lone indented line may be left empty
result = result.splitLines.filterIt(it.strip.len > 0).join("\n")2. The source. At the line jsondoc gives, the doc comment is the ## lines that follow the
declaration (a signature can take several lines first). The section is the last # ---- line
above it. The imports and the re-exports are the import, from and export lines, written in
full: import core in tabelline/verbs is tabelline/core.
docBlock: the doc comment of a declaration 13 lines
func docBlock(lines: seq[string], start: int): string =
## The `##` lines after line `start` (0-based): the doc comment of the declaration there. It
## skips the rest of the declaration (a signature can take several lines) up to the first `##`.
var i = start
var found: seq[string]
while i < lines.len and i < start + 12:
let s = lines[i].strip
if s.startsWith("##"):
found.add s
elif found.len > 0:
break
inc i
result = found.mapIt(if it.startsWith("## "): it[3 .. ^1] elif it == "##": "" else: it[2 .. ^1]).join("\n")sectionAt: the section of a line 7 lines
func sectionAt(lines: seq[string], line: int): string =
## The section of line `line` (1-based): the last `# ---- name` line above it.
for i in countdown(min(line - 1, lines.high), 0):
let s = lines[i]
if s.startsWith("# ---"):
return s.strip(chars = {'#', ' ', '-'})
""importsOf and reexportsOf 48 lines
func importsOf(lines: seq[string], module: string): seq[string] =
## The modules named by the `import` and `from ... import` lines at the top level, written
## in full: `import core` in tabelline/verbs is `tabelline/core`.
var stmts: seq[string]
var i = 0
while i < lines.len:
let l = lines[i]
if l.startsWith("import ") or l.startsWith("from "):
var st = l
while st.strip.endsWith(",") and i + 1 < lines.len:
inc i
st.add " " & lines[i].strip
stmts.add st
inc i
let dir = if "/" in module: module.parentDir else: "tabelline"
for st in stmts:
var body = if st.startsWith("from "): st[5 .. ^1].split(" import ")[0] else: st[7 .. ^1]
body = body.split(" except ")[0]
var items: seq[string]
let br = body.find('[')
if br >= 0:
let prefix = body[0 ..< br].strip
for x in body[br + 1 ..< body.rfind(']')].split(","):
items.add prefix & x.strip
else:
for x in body.split(","): items.add x.strip
for it in items:
let it = it.strip
if it.len == 0: continue
let full =
if it.startsWith("std/") or it.startsWith("pkg/"): it
elif it == "../tabelline": "tabelline"
elif it.startsWith("tabelline/"): it
elif "/" notin it: dir & "/" & it
else: it
if full notin result: result.add full
func reexportsOf(lines: seq[string], module: string, imports: seq[string]): seq[string] =
## The modules of the `export` lines at the top level, written as in `imports`.
for l in lines:
if l.startsWith("export "):
for x in l[7 .. ^1].split(","):
let x = x.strip
if x.len == 0: continue
var full = x
for imp in imports:
if imp.lastPathPart == x: full = imp
if full notin result: result.add fullAll of it is an ApiModule for each module, with an ApiSymbol for each name (its overloads
together). nim r tools/apidoc.nim prints it as JSON, for agents. Here is the smallest module:
let m = apiModule("tabelline/units")
echo m.name, ": ", m.symbols.len, " names; imports ", m.imports.join(", ")
for s in m.symbols:
echo " ", s.kind, " ", s.name, " (", s.section, ")"
tabelline/units: 6 names; imports std/strutils, std/sequtils, std/unicode, tabelline/core, tabelline/formats func formatChem (chemistry) func formatUnits (chemistry) func withUnits (chemistry) proc fmtUnits (verbs) proc fmtChem (verbs) proc colsUnits (verbs)
3. The specs. Every requirement about the API has an example with what it prints. The page
collects them with tools/specexamples.nim, runs them once, and gives each name the shortest
example that uses it.
4. gt's and Great Tables' indexes. tools/references.nim reads gt's pkgdown configuration
and Great Tables' quartodoc configuration from their repositories, and writes the names they
document to docs/coverage/references.json (committed). Two names in Great Tables' index have no
page on its site, and are left out. Rerun it when the feature map is checked for a release.
names: the names of a reference index 8 lines
proc names(yml: string, ok: set[char]): seq[string] =
## The `- name` lines of a reference index.
for l in yml.splitLines:
let s = l.strip
if s.startsWith("- ") and s.len > 2 and s[2 .. ^1].allCharsInSet(ok):
result.add s[2 .. ^1]
result.sort
result = result.deduplicate(isSorted = true)The page. docs/api.nim puts the modules in dependency order (a module goes when all it
imports is placed), gives each name its anchor, avoiding the ids of the headings, and writes
the tables with tabelline and the entries with nbApi. A long signature is cut at its
arguments, at the top-level ;, one per line.
dependencyOrder: each module after its imports 16 lines
proc dependencyOrder(listed: seq[(string, string, string)]): seq[(string, string, string)] =
## Each module after the modules it imports (the data modules are not on the page); among the
## modules whose imports are all placed, the first in `listed`.
var left = listed
while left.len > 0:
var k = 0
while k < left.len:
let m = api.filterIt(it.name == left[k][0])[0]
var waiting = false
for imp in m.imports:
if imp != m.name and left.anyIt(it[0] == imp): waiting = true
if not waiting: break
inc k
if k == left.len: k = 0 # a cycle: take the first
result.add left[k]
left.delete kanchorOf: a link that lasts 4 lines
proc anchorOf(m: ApiModule, s: ApiSymbol): string =
## An operator is spelled by its characters' codes: `&` is `core-op26`.
let name = if s.name.allCharsInSet(IdentChars): s.name else: "op" & s.name.mapIt(it.ord.toHex(2)).join
m.name.lastPathPart & "-" & namephoneSignature: one argument per line 33 lines
func phoneSignature(sig: string): string =
## A signature that fits a phone: Nim wraps at 80 columns, so a long one goes one argument per
## line instead, like a long call in the docs.
let flat = sig.splitLines.mapIt(it.strip).join(" ")
if flat.len <= 40: return flat
# the argument list: the first `(` outside brackets, and its `)`
var depth = 0
var open, close = -1
for i, c in flat:
case c
of '[': inc depth
of ']': dec depth
of '(':
if depth == 0 and open < 0: open = i
inc depth
of ')':
dec depth
if depth == 0 and open >= 0 and close < 0: close = i
else: discard
if open < 0 or close < 0: return sig
var args: seq[string]
var cur = ""
depth = 0
for c in flat[open + 1 ..< close]:
if c in {'(', '['}: inc depth
elif c in {')', ']'}: dec depth
if c == ';' and depth == 0:
args.add cur.strip
cur = ""
else: cur.add c
if cur.strip.len > 0: args.add cur.strip
if args.len == 0: return flat
flat[0 .. open] & "\n" & args.mapIt(" " & it).join(",\n") & "\n" & flat[close .. ^1]The fold that opens. A link to a name inside a closed fold would lead nowhere, so a few lines of JavaScript, shared by every page, open the folds around the target of the link, when the page loads and when the link changes.
reveal: open the folds around a link's target 10 lines
function reveal() {
var id = decodeURIComponent(location.hash.slice(1));
var el = id && document.getElementById(id);
if (!el) return;
var shut = false;
for (var d = el.closest('details.fold'); d; d = d.parentElement && d.parentElement.closest('details.fold')) {
if (!d.open) { d.open = true; shut = true; }
}
if (shut) el.scrollIntoView();
}