Simple 'Scoping' Problem
Hey,
I am very new to MPS. I am facing some issues with scoping.
I have a concept node with a string property 'p1' whose value can be either 'Optional' or 'Mandatory'. How to add scoping to this property? I want to add it in such a way that when the user presses Ctrl + Space in the editor he should be able to select any one of the value from the content assist.
Thank you.
I am very new to MPS. I am facing some issues with scoping.
I have a concept node with a string property 'p1' whose value can be either 'Optional' or 'Mandatory'. How to add scoping to this property? I want to add it in such a way that when the user presses Ctrl + Space in the editor he should be able to select any one of the value from the content assist.
Thank you.
Please sign in to leave a comment.
if I understand correctly, you want to restrict the property to two allowed values. This can be done in Constraints
concepts constraints Foo {
can be child <none>
can be root <none>
can be parent <none>
can be ancestor <none>
property {p1}
get:<default>
set:<default>
is valid:(propertyValue, node)->boolean {
propertyValue :eq: "Optional" || propertyValue :eq: "Mandatory";
}
...
}
Additionally you want to offer the two values in a code-completion menu invoked on the editor cell belonging to the property. For this you have to do two things:
1. mark the editor cell as right-transform target:
Style:
<no base style> {
<< ... >>
}
Common:
cell id <default>
action map <default>
keymap <default>
menu menu parts:
apply side transforms
side: right
tag: none
attracts focus noAttraction
show if <no condition>
2. Define a side-transform
side transform actions PropertyValues
right transformed node: Foo tag: default_ //<no description>
condition :
<none>
common initializer :
<no common variables>
....................................
<no common initializer>
actions :
add custom items (output concept: Foo)
simple item
matching text
Optional
description text
<default>
icon node
<default>
type
<default>
do transform
(model, operationContext, sourceNode, pattern, editorContext)->node<> {
sourceNode.p1 = "Optional";
sourceNode;
}
add custom items (output concept: Foo)
simple item
matching text
Mandatory
description text
<default>
icon node
<default>
type
<default>
do transform
(model, operationContext, sourceNode, pattern, editorContext)->node<> {
sourceNode.p1 = "Mandatory";
sourceNode;
}
Please check the attached project for a quick sample.
This way language extensions could provide their own kinds, for example. Also, instead of string comparison when checking the type of "p1" you could call virtual behavior methods defined on "P1Kind_whatever" in a polymorphic way.
Thanks for the solution.
I wanted to know the difference between the above method and creating a enumerated datatype for the property.
Also once the user chooses one of the property value, he is allowed to edit it. This should not happen.
Also, when I add constraints to the property, I want the user to get a personalized error instead of the default error in the tooltip.
Thanks.
Thanks for the suggestion. But in my project i have many concepts with many properties with multiple values feasible. So to define concept for each and every property value would be a tedious task. So is there any simpler solution?
Thanks.
Thanks