Search code examples
mps

How to invoke whatever generator rule is configured for a concrete instance of an abstract concept?


I have a collection of nodes of concept Command that I'm iterating over with a $LOOP$ macro. Command is an abstract concept. I have defined templates and reduction rules for concrete subconcepts, such as Outline:

template tpl_Outline
input    Outline

...

and

reduction rules:
  [concept    Outline ] --> tpl_Outline
  [inheritors false   ]
  [condition  <always>]

Question: How would I invoke the appropriate generator rule for the concrete concept from inside the $LOOP$ macro where the nodes are only known to be of the abstract type Command?

[EDIT] Since the proposed answer is specific to looping over a collection of elements, how would I do the same when there's no looping? That is, how to trigger the configured rule for a given node (e.g. a certain child of the current node).

Note 1: I tried using just $LOOP$[null], hoping for the element nodes to be processed by appropriate rules automatically, but that just produced nulls in the output.

Note 2: I tried $LOOP[$COPY_SRC$[null]], but that produced

textgen error: 'No textgen for Draw.structure.Outline' in [actualArgument] Outline null[847086916111387210] in Draw.sandbox@0

[EDIT 2] This is actually a working solution. What helped was probably invalidating the caches (just Rebuild Project was not working).

Note 3: Previously I used a template switch to call an appropriate template based on concrete concept, but I now want to support custom extensions of Command so I can no longer create an exhaustive template switch.


Solution

  • Try using $COPY_SRCL$ (L stands for Loop here), this macro is designed exactly for your situation. Also, template switches are extensible