AST/ASG Compilation Pipeline
Golem operates as a deterministic, compiler-grade document processing pipeline built on top of asciidoctrine and asciidoctype.
Pipeline Lifecycle
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
on_pre_parse: Plugins may mutate raw AsciiDoc text before parsing. Deprecated for macro expansion — useon_asg_createdinstead.- Lark AST Parsing:
asciidoctrineparses raw text into a lossless concrete syntax tree. on_ast_created: Plugins may inspect or transform the raw AST before semantic resolution.- Semantic ASG Resolution: Resolves document attributes, include directives, callout numbering, cross-references, and footnote indexing into a clean Abstract Semantic Graph (ASG).
on_asg_created: Plugins may splice, reorder, or augment ASG block nodes — the primary macro expansion site.- Node Rendering:
asciidoctyperenders each ASG block using dedicated Chameleon TAL templates. on_post_render: Plugins may post-process the final HTML fragment before layout injection.- Layout Integration: Golem injects
title,site_title,body_html,nav_tree,nav_html,toc_html,custom_css, andcustom_jsinto the theme'sskeleton.pt. - Fine-Grained Cache Invalidation: During build planning, Golem triggers the
golem_mark_stalehook, 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 |
| Standards-compliant Lark AST parser and semantic ASG resolver. |
| Template translation engine powered by Chameleon ZPT templates. |
| Python test runner extracting and executing inline doctests from AsciiDoc blocks. |
| Fast, compiled Zope Page Templates (ZPT) engine. |
| Standard Python hook and plugin management system (same engine powering pytest). |
| 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.