liveBook · Manning

Right-transform

As explained in Building User-Friendly DSLs

A side-transform that replaces an AST object with a binary operation in which the original object is the left operand and the right operand is initially unset.

A right-transform replaces an existing AST object with a Binary Operation whose left operand is that object and whose right operand is initially unset. It lets a domain expert extend an expression to the right without constructing the complete expression first. section 12.4

Implement a right-transform by:

  • Create a Binary Operation containing the selected AST object as its left operand. section 12.4
  • Call replaceWith so the existing object is replaced rather than deleted. section 12.4
  • Expose the action through a side-transform control, such as an arrow shown when the AST object is hovered. section 12.4
  • Apply the behavior generically through AstObjectUiWrapper, or enable it conditionally with a sideTransformable attribute. section 12.4

Turning 1 into 1 + ?

After entering a Number node with value 1, the user activates its right-transform and selects the + operator. The editor replaces the Number node with a Binary Operation whose left operand is 1; the right operand remains unset for the next input. section 12.4 section 12.5

Figure 12.23 Right-transforming an existing AST for the expression <left> into an AST representing “<left><op> ?”
figure

Use the AST diagram to follow how an existing expression becomes “<left><op> ?” and how the original node becomes the left operand. section 12.4

How Building User-Friendly DSLs covers it

How deep it goes
Defines the AST transformation and gives UI and replaceWith implementation patterns, but defers full expression construction and precedence behavior.
Examples
Uses the incremental expression 1 + 2, Number-node projections, arrow controls, and Binary Operation replacement listings.
What it assumes
Assumes AST objects, parent-child AST structure, and projection callbacks; teaches the right-transform operation from the concrete 1 + 2 workflow.
What you can do after
Build projectional-editor interactions that extend AST expressions to the right through reusable replacement callbacks and UI wrappers.
How it connects
Connects ASTs, binary operations, side-transforms, left-transforms, operator precedence, associativity, and projectional editors.

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.