Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Call from another language

Problem. You are not writing Rust — you want to parse Aozora notation from Go, Java, Python, JavaScript, Ruby, PHP, or something further down the long tail.

One parser, many front doors

There is exactly one parser. Every binding funnels the same source text through the same lexer and emits the same HTML, the same canonical serialise, and the same wire-envelope JSON — byte-identical across every language. So the decision is not “which binding is more correct”; it is “which fits the language and runtime I already have.” Choosing a binding is the full decision table; this recipe is the short jump list.

Pick your language

  • JavaScript / TypeScript (browser, Node, Deno, edge) → aozora-wasm. A wasm-bindgen Document class; runs client-side and at the edge, distributed on npm.

  • Pythonaozora-py. An in-process PyO3 native module built with maturin:

    from aozora_py import Document
    doc = Document("|青梅《おうめ》")
    print(doc.to_html())     # <ruby>青梅<rt>おうめ</rt></ruby>
    
  • Goaozora-go. A pure-Go wazero host over aozora.wasmno cgo, no C toolchain:

    go get github.com/P4suta/aozora-go
    
  • C / C++ / Zig / any FFI-capable native language → the aozora-ffi C ABI: an opaque handle plus JSON over a stable C header (aozora.h).

  • Java, PHP, Ruby, .NET, Elixir, Haskell, … the long tail → the aozora-extism host SDK. One portable aozora.wasm that any Extism host SDK loads — see below.

  • Anything other than HTML (EPUB, LaTeX/PDF, DOCX, …) → the aozora pandoc pipe, regardless of host language.

The Extism template (the breadth strategy)

For the languages without a bespoke native binding, the answer is the single aozora.wasm artifact loaded through that language’s Extism host SDK. The steps are identical in every SDK — only the method names change:

  1. Obtain aozora.wasm (a GitHub release asset).
  2. Load it with your host SDK’s plugin constructor (no WASI needed).
  3. Assert schema_version matches the wire schema you compiled against.
  4. Call an export with the source string:
    • to_html / serialize → a bare string;
    • diagnostics_json / nodes_json / pairs_json / container_pairs_json → a { schema_version, data } wire envelope.
  5. Parse the envelope data with types generated from the committed JSON Schema.

The reference host SDK (aozora-go) is exactly this template instantiated in Go; every other Extism SDK follows the same shape. The full export list and the language-agnostic walkthrough live in the Extism chapter. Why a wasm plugin for the tail rather than a native binding per language is ADR-0006; the short version is in Choosing a binding → In-process vs host-runtime.

See also