Skip to main content

Golem Documentation

Michael Bernstein

AST/ASG Compilation Pipeline

Golem operates as a deterministic, compiler-grade document processing pipeline built on top of asciidoctrine and asciidoctype.

Pipeline Lifecycle

Compilation Pipeline Data Flow
TEXT
 Source .adoc File
       │
       ▼ [on_pre_parse hook] ← Plugin text pre-processing (deprecated for macro use)
       │
       ▼ [1. Parse] (asciidoctrine.parse_to_ast / Lark)
 Concrete Syntax Tree (AST)
       │
       ▼ [on_ast_created hook] ← Plugin AST transforms
       │
       ▼ [2. Resolve] (asciidoctrine.resolve_to_asg / Semantic Analysis)
 Abstract Semantic Graph (ASG Node Dictionary)
       │
       ▼ [on_asg_created hook] ← Plugin ASG transforms & macro splicing ★
       │
       ▼ [3. Render] (asciidoctype.AsciiDoctypeRenderer / Chameleon ZPT)
 HTML5 Fragment (body_html)
       │
       ▼ [on_post_render hook] ← Plugin HTML post-processing
       │
       ▼ [4. Layout Template] (skeleton.pt / TAL Slot Insertion)
 Full Static HTML5 Document (dist/*.html)

★ on_asg_created is the preferred hook for block-level structural transforms such as golem.apidoc:: macro splicing. It receives the fully resolved ASG after all cross-references and include directives are settled.

Pipeline Stages

  1. on_pre_parse: Plugins may mutate raw AsciiDoc text before parsing. Deprecated for macro expansion — use on_asg_created instead.
  2. Lark AST Parsing: asciidoctrine parses raw text into a lossless concrete syntax tree.
  3. on_ast_created: Plugins may inspect or transform the raw AST before semantic resolution.
  4. Semantic ASG Resolution: Resolves document attributes, include directives, callout numbering, cross-references, and footnote indexing into a clean Abstract Semantic Graph (ASG).
  5. on_asg_created: Plugins may splice, reorder, or augment ASG block nodes — the primary macro expansion site.
  6. Node Rendering: asciidoctype renders each ASG block using dedicated Chameleon TAL templates.
  7. on_post_render: Plugins may post-process the final HTML fragment before layout injection.
  8. Layout Integration: Golem injects title, site_title, body_html, nav_tree, nav_html, toc_html, custom_css, and custom_js into the theme's skeleton.pt.
  9. Fine-Grained Cache Invalidation: During build planning, Golem triggers the golem_mark_stale hook, allowing themes and plugins to selectively invalidate cache for specific templates or document nodes based on metadata.

Core Dependencies

Golem's pipeline is assembled from focused, independently testable Python libraries:

Library

Role

asciidoctrine

Standards-compliant Lark AST parser and semantic ASG resolver.

asciidoctype

Template translation engine powered by Chameleon ZPT templates.

asciidoctest

Python test runner extracting and executing inline doctests from AsciiDoc blocks.

chameleon

Fast, compiled Zope Page Templates (ZPT) engine.

pluggy

Standard Python hook and plugin management system (same engine powering pytest).

click

Composable command-line interface toolkit.

AST (Abstract Syntax Tree)

The initial parse tree produced by Lark from raw AsciiDoc source, before semantic resolution.

ASG (Abstract Semantic Graph)

The resolved, typed graph of document nodes produced by AsciiDoctrine after the AST stage. Golem operates on the ASG rather than the raw AST.

DAG (Directed Acyclic Graph)

The dependency graph connecting document nodes. Golem's pipeline ensures the DAG has no cycles so nodes can be resolved in a deterministic topological order.