Exchanging Node with Node of allowed Concept

Hello

I would Like to exchange a node in an baseLanguage AST with an empty node that is allowed in the former nodes position. I will call those two Nodes OriginalNode and ExchangeNode.

Just accessing the OriginalNode's concept and creat a new instance of it doesn't do me much good. Because it restricts me to one Concept. Also the Concept of the OriginalNode might be a subconcept of the allowed concept at this position, or even worse, there are multiple distinct Concepts allowed.

What i would like to do is to access the parent of the OriginalNode and look what concepts are allowed by looking up the concepts of the children defined in the parent. With this information I would like to give the user a possibility to choose the concept. Beside the fact that I dont know yet how to give the user the possibilty to choose, my real problem is that I dont know how to access the Information in the parent of the OriginalNode.

If someone could give me a hint how to do that, I would appreciate it.

Jochen
8 comments
I'm not 100% sure what you want to achieve but you could define a node attribute for any concept and define an editor for it.
You can for example hide any node with this approach(more info here) or access information of the original node (by calling .parent on the attribute). The attribute can be added programmatically:

node.@YourAttribute = new node<YourAttribute>();
prettyPrint();
0
In addition to fxlex's answer you also want to derive from that I call it generic concept. If your user presses CTRL+SPACE, he will get IntelliSense and you don't need a comboxbox or something similar.

HTH
0
First thx for the answers, but that only helps me partly.

Conceptual I am pretty clear what I want to do. But I have a problem finding the right "calls" in the API. I think it will be either in the SModel or the OPEN Api, but I just dont know how to achieve it.

Lets make an example.

Structur A:

children1 : children1Typ [0..n]
children2 : children2Typ [1]

Now I have an AST that looks kinda like this :

              A
chi1d1a    child1b    child1c     subTypeOfChild1     child2

Lets assume the current node I am "in" is the subTypOfChild1 node :

I now want to know all Concepts that are allow in the position of subTypeOfChild1. I assume it would kinda look like this :

subTypOfChild1.parent.model. ????? children. ??? getALLConcepts

or maybe somehow iterationg over all children and saving all found concepts. Maybe I should clarify that I want to access the Informtion in the Definition of A, not the Information in the node of type A , becuase the node of type A might not give me ALL POSSIBLE Concept, as some child node that is possible might not be present in the current AST I am in.

Thx for reading.

Jochen
0
For the example you provided, what would be your expected result for the request? I think "valid" concepts of nodes that can replace "subTypeOfChild1" are all concepts in the concept hierarchy of "children1Typ". "Valid" here also depends on the used type system, as well as the search scope, does it not?

Or do you mean to find all concepts used in the current tree that could replace the one of your current context? I.e., in the example the result you are seeking would be a collection of "children1Typ" and "subTypOfChild1", since both have instances in the tree?

If an API like getALLConcepts exists, and I unfortunately don't know if it does, you would have to provide the scope.
What might be worth a look (haven't any experience with it, but it might just be what you are looking for, is "concept" and "sub-concepts").

Something like:
node.parent : A.children1.concept.sub_concepts(...)

Look at https://confluence.jetbrains.com/display/MPSD33/SModel+language+Queries , section Migrating away from deprecated types.
0
As you said, I would like to find all Concepts and Subconcepts of the Children allowed by "A".

As my position is childOfA the call to get to the concept of A would be like  :

childofA.parent.Concept

now here is my problem. From here I would like to iterate over all defined children ,in the "concept"/defintion of A, and find their concepts. I am not sure if I use the term "concept"/definition correctly, but I am talking about the defintion in the structure folder of language, not the node that is an instance of the definition.

Doing somehting like

childofA.parent.children

and then iterate over the concrete children (nodes) in the AST is not a correct way because i might miss out on some possible concepts and subconcepts.
0
Hm, I think to make sure we are on the same page, you should tell us what your expected result would be in your example above for "I would like to iterate over all defined children ,in the "concept"/defintion of A and find their concepts"

the children of concept A are called "children1" and "children2" (I think of those as names of traits under a node that "group" children).

Again, I'm not able to test it myself at where I am right now, but did you try node.parent.concept.asNode.children? This should give you "children1" and "children2" for your example, if I'm not mistaken.
0
Now I feel stupid. I didnt see the "asNode". I couldnt call ".children" on concept. Thank you very much for the help.
The expected result would be {children1Typ , children2Typ} .
0
Don't, I feel like that all the time learning a new technology (MPS is far from being an exception). Just keep going!
0

Please sign in to leave a comment.