liveBook · Manning

Ancestor list

As explained in Building User-Friendly DSLs

An array containing the AST objects that contain a currently projected AST object, ordered from the nearest parent to the root.

An ancestor list is an array of AST objects containing the currently projected AST object, ordered from its nearest parent toward the root. It lets Projection travel upward through containment relationships instead of receiving only one parent. section 5.4

Use the list while recursively projecting an AST:

  • Start the root projection with ancestors={[]}. section 5.4
  • Pass ancestors={[astObject, ...ancestors]} when projecting each contained object, preserving nearest-first order. section 5.4
  • Find required context with ancestors.find, such as the enclosing Record Type or Data Attribute. section 5.4

Resolving an attribute reference

An Attribute Reference searches the ancestor list for a Record Type, reads its attributes, and uses those attributes to populate the reference dropdown. section 5.4

Figure 5.12 Finding all attributes in the record type by traversing up the example AST from the attribute reference
figure

Trace the upward traversal from an attribute reference to its enclosing record type. section 5.4

How Building User-Friendly DSLs covers it

How deep it goes
Defines ordering and propagation, then demonstrates recursive passing and ancestors.find lookups in Projection.
Examples
Demonstrates empty root context, spread-based recursive propagation, and attribute-option lookup for an Attribute Reference.
What it assumes
Assumes AST objects and Projection, while demonstrating ancestor context from the root upward.
What you can do after
Build context-aware projections that resolve enclosing record and attribute information during AST rendering.
How it connects
Connects AST traversal with Projection, Attribute Reference, Record Type, and Data Attribute.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.