Route an extension to an existing parser
Many formats are plain text, code, INI, XML or a zip that an existing module already reads. Do not write a crate for them, and do not leave them as a hex stub. This page routes such a format to the module that reads it.
Before you start
- A corpus sample of the format in
poka-samples. - The wasm module you want to reuse, built for
wasm32-wasip1(see Write a parser).
Steps
Run the candidate module on the sample. Use wasmtime and read the output. Route the format only if the preview is right, not merely non-empty.
Pick the form of the route.
- It is genuinely the same format as the module's own (
.ppsxonpoka-pptx): add the extension to thealiaseslist of that module'splugin.json. - It needs its own id, name or registry row (
poka-xltonpoka-xls.wasm,poka-docmonpoka-docx.wasm): add one line toparsers/aliases.toml.
- It is genuinely the same format as the module's own (
Write the
aliases.tomlline (skip this step for analiasesentry):poka-xlt = { module = "poka-xls", ext = ".xlt", name = ".xlt Preview" }The caps,
viewerand wasm come from the module's own manifest. Setmemory_mbandmax_time_msonly where they differ.aliasesanddisabled_reasonare the other optional keys.Update the format's
FILE_FORMATS.csvrow:WasmModules,Viewer,ParserTypeandWasmRoute.Add a case to
scripts/test-routed-samples.py: the route id, the corpus sample and two or three strings taken from the sample's own content. The script resolves the sample's extension through the expanded manifests, runs the route's wasm underwasmtimewith the route's caps, and fails unless the module reported those strings.--dump <route-id>prints what the module reported, to pick them from.Run the checks:
cargo build --release --target wasm32-wasip1 -p <module> python3 scripts/test-routed-samples.py <route-id> python3 scripts/check-parser-invariants.py python3 scripts/test-manifests.py python3 scripts/sync-file-formats.py --check python3 scripts/scorecard.py # then commit docs/scorecard.md
Do not
- Do not create a
parsers/poka-<ext>/directory that holds only aplugin.json. With noCargo.tomlit breaks every cargo command with "failed to load manifest for workspace member". - Do not claim an extension that another module already owns. One handler per
file extension;
test-manifests.pyfails on a clash.
The checks and the release archive expand aliases.toml lines into manifests
with scripts/_manifests.py, so a route cannot drift from the binary it runs.
See also
SPEC.md— routing rules in the parser contract.- Test a parser — check the routed format on the corpus.