Guidedog 설명서 1.0.0-beta.16
언어
이 페이지의 내용
Guidedog / 문서 1.0.0-beta.16

The Guidedoc engine

Guidedoc is the conversion core: the guidedoc crate and the reader and renderer crates it registers. It reads a source, builds a validated semantic tree, runs passes, and renders bytes. It does not open files, run compilers, or publish artifacts. The host does that. The engine crates use only the standard library, so another program can embed them.

The CLI calls the project host, which owns workspaces and runs the conversion core; the host also drives Graphviz, Typst and tree-sitter.
그림 31 Effects belong to the host; document semantics belong to Guidedoc.

Crates and their direction

Dependencies point one way: the engine knows nothing of the crates above it.

guidedoc

The AST, the builder and validator, diagnostics, the adapter registry, symbol tables, the object format, and the conversion pipeline.

Readers and renderers

guidedoc-rst (with guidedoc-rst-inline), guidedoc-commonmark (CommonMark and MyST), guidedoc-sphinx (Sphinx directives, roles and domains, including the odin and rust domains), guidedoc-cpp; guidedoc-html, guidedoc-typst, guidedoc-text, and guidedoc-rst-writer.

guidedoc-defaults

The built-in registry, and the adapter that joins gd-highlight to the engine’s Highlighter trait.

The host

gd-host meets the operating system: sessions, confined files, atomic publication, the coarse budget, worker threads, crash reports. The project builder (gd-conf, gd-env, gd-read, gd-resolve, gd-link, gd-outputs, gd-site, gd-book, gd-intl, gd-project) and gd-cli sit above it, and cmd/guidedog is the program.

Supporting libraries (gd-toml, gd-json, gd-jinja, gd-highlight, gd-gettext, gd-graphdog, gd-typst, …) never depend on guidedoc; only adapters join them to the engine. Typst lives only inside gd-typst.

Conversion data flow

A document passes through distinct stages. Each stage works in the caller’s Workspace, which keeps its buffers between conversions:

Source text becomes a flat tree. Passes transform it. One rendering run writes into a bounded emitter.
그림 32 Conversion data flow within the Guidedoc engine.

The staged calls are read_document, transform_document, check_render and render_document. convert runs them for one request. convert_text is the one-call path with a default request:

use guidedoc::{convert_text, Workspace};

let registry = guidedoc_defaults::registry();   // the built-in readers and renderers
let mut ws = Workspace::new();                  // reuse it: buffers are kept
match convert_text(&mut ws, &registry, "commonmark", "html", "# Hello\n") {
    Ok(html) => println!("{html}"),             // borrows ws until the next convert
    Err(fail) => eprintln!("{fail}"),           // title, message, and hint
}

Every failure is a Fail { status, need, diagnostic }. The status is the class (InvalidInput, Unsupported, Policy, Capacity, Limit, Cancelled, Internal). The diagnostic has a stable code, a title, a message, and a hint.

The boundary

The workspace owns its tables as Vec and String values. It clears them between conversions and keeps their capacity, so the engine’s own work in steady state allocates nothing. A test with a counting allocator checks it. Readers and renderers keep their working state in the workspace’s Scratch store too; a second counting-allocator test bounds any remaining warmup or lossy-report allocations per reader and renderer pair and checks that they do not grow (see Memory and ownership and Testing). Growth driven by the input uses try_reserve and stays within Limits (nodes, text bytes, output bytes, reports, depth, work, stack, includes). So running out is a Capacity or Limit result, never a panic. A third-party compiler has its own allocation rules. The guarantee covers the conversion boundary, not the whole process. See Memory and ownership.

The tree

Nodes have newtype ids (NodeId(u32)). Hot columns hold the kind and the subtree range; cold tables hold the payloads particular kinds need. A flat preorder Vec lets a traversal skip a whole subtree without following pointers.

For node \(i\), let \(e_i\) be its exclusive subtree end. The subtree occupies \([i,e_i)\). A leaf has \(e_i=i+1\). A parent closes after its descendants. See Invariants before algorithms for the interval proof and Guidedoc AST contract for the normative node shapes.

The API

The API has few concepts and plain data. Requests are public-field structs built from default_request with struct-update syntax. Registries are immutable values holding reader, pass, and renderer descriptors. There is no runtime plugin discovery and no global registration. Readers are Reader constants whose read function builds nodes with the builder. Renderers walk the document and write to the emitter. A pass is a closure that returns Unchanged at no cost or copies what it keeps into a rebuilt tree.

Ownership is the key rule, and the compiler enforces it. A Document<'ws> borrows its workspace, so a document or an output cannot outlive the next conversion, and a stale or foreign handle does not compile, so no generation or revision check is needed at run time. A result the host keeps must own its text. The crate’s README.md is the API cheat sheet. The generated reference is guidedoc, and the design record is GDS 0003 in docs/gds.