Module inheritance

Module inheritance 

Source
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 font

After resolution, the child template contains merged styles where child fields override parent fields.

§Algorithm

The resolution uses depth-first search (DFS) with cycle detection:

  1. Start from the child template
  2. Walk up the extends chain collecting ancestors
  3. Detect circular inheritance (visited set)
  4. Merge from root to child (parent first, child overrides)
  5. Return fully resolved template with no extends field

§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§

TemplateProvider
Trait for looking up templates by name during inheritance resolution.

Functions§

resolve_template
Resolves a template’s inheritance chain into a fully merged template.