How to move root nodes from transient to non-transient models?

It's possibile at the end of the generator process to move roots nodes to a language or a solution?
If I try to do it with a post-processing script using a runWriteAction() MPS reports the error "dead-lock prevention: do not start write action from read".
But I don't know if the whole generator runs inside a read action, and so the answer is "not possible" or somewhereelse the generator can execute write actions.

Thx,
Mar
7 comments
Look at this thread:
http://forum.jetbrains.com/thread/Meta-Programming-System-1015

Have you tried that snippet?
ModelAccess.instance().runWriteActionInCommand(new Runnable() { 
      public void run() { 
        // change your properties
      } 
    });
prettyPrint();
0
Thx for helping, however that was not a solution, the error changed in "Access is allowed from event dispatch thread only."
Mar
0
Marco, if I recall correctly, post-process scripts give you the option of write access. It should say read by default, but this can be changed. Trying to override inside the script is too late, I would try  changing the script from read access to write access.
0
Hi Fabien,
I have made another try with your input: the possibility to modify the model is given from a pre-processing script but not from post-processing, but this would not be an issue because I could create 2 mapping configuration and run my script as pre-processing script of the second mapping configuration.

However even in a pre-processing script with modifies model = true an error is fired, either "dead lock prevent" or "Access is allowed from event dispatch thread only." depends on the runWriteAction method used.

Let me clarify that I should not modify the given transient model but a "persistent/non-transient" model, for example the structure model of a language.
I'm starting to think that generator is not intendent for this, rather the generator only creates transient model to be used as input for TextGen. Below my test script, using runWriteActionInCommand just change the fired error:
mapping script copyConcepts

script kind : pre-process input model
modifies model :true

(genContext, model, operationContext)->void { 
  final model s = LanguageAspect.STRUCTURE.get(language-module/org.mar9000.mps.DOT/); 
  ModelAccess.instance().runWriteAction(new Runnable() { 
    public void run() { 
      s.add root(<concept Test extends BaseConcept implements <none>
instance can be root: false 
alias: <no alias> 
short description: <no short description> 
 
properties: 
<< ... >> 
 
children: 
<< ... >> 
 
references: 
<< ... >>
>); 
    } 
  }); 
}
prettyPrint();
0
Indeed, Generator is not true Model-to-Model transformation tool. It ends up with transient models. M2M story is almost non-existent in MPS, unfortunately (sound external advocate would not hurt, you know ;)
Do you need to move nodes as part of generation or you could afford to accomplish that as a separate step? E.g. distinct UI action may do the trick.

I'm puzzled to see post-processing doesn't allow you to modify a model, provided you modify the same model you transform. Transient models shall be possible to modify from post-processing script, and I'm pretty sure it works as we use post-processing scripts in MPS generators.

FWIW, never ever use static ModelAccess.instance(), it's deprecated. Obtain one from SRepository or a Project. As a general advice, please respect deprecated marks (we truly mean it!) and update your code as soon as you encounter them (unless you're ready to fix the code each time you switch to new MPS release)
0
Hi Artem,

I faced this problem in the context of PE4MPS project (https://github.com/mar9000/pe4mps) where I parse a textual description of a language (more or less the language's grammar) and generate the language's artifacts (structure, editor...), so the models I'm trying to modify (with write actions) are the structure model, editor model... of a real MPS language.
This is why I need to persist the result of the M2M transformation or write/copy its content to non-transient model.
Yes I'm not modifing the model I'm generating, I read from it to modify language's models.

Your hint was very usefull to confirm that the actual strategy (plugin + UI actions + programmatically create concepts using quotations) it's the only existing one.

I trust you but let me say that the "M2M story" seems to me almost there, just give a way to persist transient models :-) or copy their content to non-transient models.

Thx for helping,
Mar
0
strategy (plugin + UI actions + programmatically create concept using quotations) it's the only existing one

I'd avoid quotations, to me, it looks impossible to build a whole language just with quotations ;)

Scenario I had in mind is generator run and subsequent manually-invoked action on a transient outcome to build a new language. This approach has benefits as you can confirm transient models are ok prior to overwriting structure/editor aspects of your intermediate target language.

If you don't like the idea of distinct step to 'move' transient models into 'stable' language aspect models, you could implement your own make action, which would invoke Make as regular Make Model action does, and then consume transient models any way you like.
0

Please sign in to leave a comment.