mps

Access node's properties/children from inline template


I have a template switch where, based on the node's concept, I want to create runtime objects using that node's properties and/or children. The right-hand side of each case is an inline template. How do I access node's properties/children from that inline template? More specifically, in the screenshot below, the arguments to the line() and rectangle() methods need to be extracted from the corresponding LineCommand and Rectangle nodes.

Note that the Alt+Enter menu doesn't offer to "Add a Property Macro".

I am using MPS 2018.1.5.

enter image description here


Solution

  • In order to extract an argument from the node's children you need to add the template argument (e.g. "null") and then put the macro on it. Then in the process of generation, the template argument (null) will be replaced with the generation target of the node's children. If you want to use the node's property, then you should add a more specific argument (e.g. empty string) and put the caret to the property cell (between the quotes) and then you will see the "Add Property Macro" intention

    template argument

    template argument

    template argument with the property

    template argument with the property

    add property macro

    add property macro