liveBook · Manning

Attribute reference

As explained in Building User-Friendly DSLs

A structured object that identifies an attribute as the target of a reference.

An attribute reference is an AST object that identifies a Data Attribute as the target of a reference. Its attribute setting holds a reference relation to the target attribute, rather than containing that attribute. This lets one attribute use another attribute’s value while preserving the containing AST tree. section 2.2

Referencing a rental price

An initial value for rental price after discount can be an Attribute Reference whose attribute setting targets rental price before discount. In the projected DSL, the target name is rendered as “the rental price before discount.” section 2.2 section 4.2.3

A usable attribute reference needs a target-aware projection and editing flow:

  • Project the target’s name by following settings["attribute"].ref to the referenced Data Attribute and reading its name; style the result as a reference. section 4.2.3
  • Find the containing Record Type through ancestor objects, then offer all of its attributes as drop-down choices. section 5.4
  • When a user chooses a name, store a reference wrapper whose ref points to the matching attribute object. section 5.4
  • Allow Attribute Reference as one of the two selectable concepts for a newly added initial value; handle an unchosen target as a placeholder state. section 6.1.2

References require checks beyond successful JavaScript execution. A missing target is an issue, and an attribute reference used as an initial value must target an attribute with the same type as its containing attribute. Ancestors provide the containing attribute; the reference provides the other attribute. section 9.3.3

Attribute Reference can also serve as an expression: it evaluates to the value held by its referenced attribute at evaluation time. Referenced Data Attributes remain outside an expression AST’s containment structure. section 11.1

Figure 2.16 Representing an initial value that is a reference
figure

Shows the distinction between containing an Attribute Reference as an initial value and referencing the separate target attribute. section 2.2

How Building User-Friendly DSLs covers it

How deep it goes
Defines representation, projection, editing, creation, and type-checking behavior, then specifies evaluation as an expression.
Examples
Uses rental price after discount referencing rental price before discount, plus mismatched percentage and amount attributes.
What it assumes
Builds from AST containment and reference relations while introducing ancestor traversal for context-dependent reference handling.
What you can do after
Apply it via React and MobX to project, select, create, and validate references among record-type attributes.
How it connects
Connects Data Attribute, AST, containment relation, reference relation, Record Type, Number, Binary Operation, and type checking.

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.