liveBook · Manning

Reference wrapper

As explained in Building User-Friendly DSLs

A JavaScript object containing a reference marker and target reference so that a reference can be distinguished from an encoded AST object.

A reference wrapper is a JavaScript object containing a ref property that points to another AST object. It makes a reference distinguishable from a contained encoded AST object. section 3.1.2

Use a wrapper when a setting refers to an existing AST object. The target is retrieved by evaluating the wrapper’s ref property; this operation is dereferencing. section 3.1.2

Rental-price reference

The initial value for rental price after discount refers to the rental price before discount attribute through { ref: rentalPriceBeforeDiscountAttribute }. The target is accessed as rentalPriceAfterDiscountInitialValue.settings["attribute"].ref. section 3.1.2

const rentalPriceAfterDiscountInitialValue = {
    concept: "Attribute Reference",
    settings: {
        "attribute": {
            ref: rentalPriceBeforeDiscountAttribute
        }
    }
}

Inspect the wrapper embedded in the Attribute Reference AST object. section 3.1.2

How Building User-Friendly DSLs covers it

How deep it goes
Defines the wrapper shape, explains target retrieval, and stops short of using ID-based references.
Examples
Uses rental-price attributes and an Attribute Reference AST object to demonstrate reference encoding.
What it assumes
Assumes encoded AST objects and JavaScript object references as the surrounding representations.
What you can do after
Apply it via JavaScript to encode references and retrieve their targets through the ref property.
How it connects
Connects AST objects, JavaScript object references, reference relations, and dereferencing.

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.