Ways of constraining options based on a reference (like overloading functions)

Hi,

I have a node that has a single reference and several children that represent operations on the target of the reference. The operations need to be constrained by the type of the target. In other words, the user will choose a reference, and this will determine what operations the user sees as options on it (kind of like overloading functions).

Where in MPS is the best place to implement this functionality? The option I am using now is ok-ish: I am adding a constraint to the relevant statements such as "parentNode : MyParentConcept.reference.concept.isExactly(TheConstrainingNodeType)", but I was wondering if there are more elegant options (or better ways to check). If I could automatically add a child based on the type of reference the user selects, that would be nice. For example, if the user selects "Fruit" as the reference, I could automatically add a "FruitStatements" child that could then allow for the appropriate statement children.

Also, I was wondering if there is a good way to mark that a node can be the target of certain statements. For example, if another statement results in something that can be the target of "FruitStatements", what would be an elegant way to mark this? A somewhat constrained option would be to mark that type of statement with an interface and then look for its presence.

Thoughts/advice?

Thanks.

3 comments

One thing that would be extremely useful is if I could convert a node into a different node based on some conditions. For example, if my "Fruit" node has children of the type "FruitAction", and one of these actions is "Dice", it would be nice to be able to transform (or wrap) the parent into a "DicedFruit" node. Then I can have this node pop up as an option whenever I need a DicedFruit action.

I know this can be done in generation, but I am interested in it for use in the editor, so that operations can always be performed on relevant nodes (nodes that both started as "DicedFruit", and fruit that has been "Diced").

Is there a good way to do this? It seems like Node Factories are only used when instantiating a node explicitly, and side transformations occur only when text is added to the left or right. Where can I manipulate the syntax tree based on specific conditions such as adding a "DicedFruit" action?

0

^ Correction to that example, should be "such as adding a "Dice" action (node)

0

To me this sounds like a case for the "wrapper" substitution - see, for example, "expressionStatement" that converts an Expression into a Statement, when needed.

Vaclav

 

0

Please sign in to leave a comment.