Expand description
Template inheritance resolution with DFS and circular detection.
This module implements the inheritance chain resolution algorithm for
Blueprint templates, supporting the extends keyword for template reuse.
§Inheritance Model
Templates can extend parent templates using the meta.extends field:
# parent.yaml
meta:
name: parent
styles:
body:
char_shape: { font: "Arial", size: 10pt }
# child.yaml
meta:
name: child
extends: parent
styles:
body:
char_shape: { size: 12pt } # Overrides only size, inherits fontAfter resolution, the child template contains merged styles where child fields override parent fields.
§Algorithm
The resolution uses depth-first search (DFS) with cycle detection:
- Start from the child template
- Walk up the
extendschain collecting ancestors - Detect circular inheritance (visited set)
- Merge from root to child (parent first, child overrides)
- Return fully resolved template with no
extendsfield
§Merge Semantics
- Styles: Field-level merge (child fields override parent fields)
- Page: Child’s page entirely replaces parent’s (if present)
- Markdown mapping: Field-level merge (child entries override parent)
Constants§
- MAX_
INHERITANCE_ DEPTH - Maximum inheritance depth to prevent infinite recursion.
Traits§
- Template
Provider - Trait for looking up templates by name during inheritance resolution.
Functions§
- resolve_
template - Resolves a template’s inheritance chain into a fully merged template.