Replacing child role


Let's I tried to exlain on example... I have document:


Seq2 {Type1} ::= SEQUENCE {

    a1 Type1

   } --Sequence type assignment (1)

  Seq ::= SEQUENCE {
    b1 INTEGER,
    COMPONENTS OF Seq2 {BOOLEAN} --Creating of (1) with actual parameters (2)

  seq Seq ::= {
    b1 123,
    a1 TRUE --Reference to the a1 named type (3)

  How it works in a coupe of words: first of all I declare sequence type (1), at the second (2) point I create copy of (1) and replace Type1 parameter with BOOLEAN type and at the third point I reference to the a1 named type in the CLONE of (1) with actual type. But when I restart MPS reference to the a1 losts, I tried to set cloned node value to the child of concept, that MPS save clone node, but it throws exception:

  Caused by: jetbrains.mps.smodel.IllegalModelChangeError: registered node can only be modified inside undoable command or in 'loading' model [componentOfType] ParameterizedType <no name>[1048767958317438942] in Test.sandbox

What you advise in this case?

Best regards,


Comment actions Permalink

Ok, I found the way to set value to child - setLoading method of model concept shoud be called with true parameter.

But one another problem appeared - after every clone operation, the (3) reference losts, because how I understand after cloning node ids changes :-(

Can anybody suggest other ideas how to implement this?



Comment actions Permalink


Sorry for not answering you for so long.

You are wrong with loading state. The loading state is implemented to load models without listeners invocation (this is only for performance reasons and only for model loading process). After the model is loaded, it can only be modified inside "commands". We plan to add many assertions for this in 1.2, so it's better not to use loading state if you are not loading your model.

Now DSL constructs for commands are placed in jetbrains.mps.lang.plugin language. So, you can import the language and type "command". You'll get a block inside which you can change nodes.

But it's very strange that you need to use commands if you are not working with IDE-related aspects like plugin (Btw, where do you clone your nodes? In actions?). If you could provide a stacktrace for this error, maybe I could say what went wrong actually. Commands is not what regular MPS user should know about, so we surround almost all user code calls with approprite commands, and you don't normally need to write them manually.




Please sign in to leave a comment.