Creating new root nodes from generator pre-processing script

I'm trying to create new Root Node from a mapping script (pre-process input model, modifies model).

Script inspects existing nodes and creates something like 'all-together' node of the same kind as other root nodes. root node(...) or root node(...)

I see my created node in transient models at step 1_0, it is not distinguishable from other similar nodes.
However, on the next step (in transient models), all nodes except this new are correctly transformed according generator mapping. This new node remained as is (in source language).

Calling .isDurty on this node causes:
[jetbrains.mps.generator.impl.dependencies.IncrementalDependenciiesBuilder] consistency problem in dependencies map

Textgen is correctly applied to original root nodes transformed to target language, but newly created node remains unchanged.

My question is, are mapping scripts allowed to create new root nodes?
Although it is possible technically, it is much better to avoid model modifications in scripts. Especially adding the root nodes.

1. Generator cannot trace node flow in a script. Generation dependencies are not properly collected and subsequent generation cannot be done incrementally.
2. Mapping scripts are not paralleled.
3. Scripts are imperative (hard to read and support).

The best place to create the collect-all-in-one root is conditional root section of mapping configuration. Create root rules are applied before any other rules at the beginning of the major step (right after pre-processing scripts).

Proper usages of mapping scripts are visiting the model to prepare data for reductions, annotating nodes and may be updating properties or references, i.e. without changes in the containment tree. Mapping scripts are a place to collect model-wide data, not to perform model transformation.

Anyway, creating a new root node should work. There may be issues with incremental generation, try to turn it off (Settings -> Generator) to see if it affects reduction of created nodes (I don't believe in it though). Consistency problem is a bug. We'll fix it.
Ah, that's the meaning of 'conditional root rules' - it allows creating new root nodes.

Thanks! Now it works perfectly; I removed the script replacing it with template-based rule with <unspecified> input.
Yeah, conditional root rules are intended to create descriptors like plugin.xml or web.xml, where you put references to existing entities or embed some integration code.

Input node in all queries is null (unless under the $LOOP$ macro).

Please sign in to leave a comment.