liveBook · Manning

Side-transform

As explained in Building User-Friendly DSLs

A transformation of an abstract syntax tree that replaces a specified AST object with a binary operation containing that object as an operand.

A side-transform replaces a selected AST object with a Binary Operation node that retains the object as its left or right operand. A right-transform extends an expression to the right: the existing object becomes the left operand and the new right operand remains unset. section 12.4 section 12.5

In a projectional editor, side-transforms let domain experts begin with a Number such as “1,” then convert it into a binary operation instead of planning the complete expression first. This reduces editing actions and supports character-by-character expression building. section 12.4 section 12.5

A practical right-transform implementation follows these steps:

  • Replace the selected AST object through the parent property's replaceWith function. section 12.4

Turning “1” into “1 + ?”

When the user activates the right-transform on a Number AST object, replace it with newAstObject("Binary Operation", { "left operand": astObject }). The user can then select “+” and fill the remaining operand.

How Building User-Friendly DSLs covers it

How deep it goes
Defines left and right variants, explains parent replacement, and demonstrates generic UI integration; it stops short of broader transformation algorithms.
Examples
Uses character-by-character construction of “1 + 2,” Number projections, AST diagrams, replaceWith listings, and hover-triggered UI controls.
What you can do after
Build it from scratch by implementing a right-transform, wiring replacement callbacks, and exposing reusable editor controls.
How it connects
Connects ASTs, binary operations, projectional editors, replaceWith functions, operator precedence, and associativity.

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.