A Simple Constraint

Hello, 

I'm very new to MPS and I'm following the fast track. It should be the simplest problem but I don't seem to find the answer. 

I have a concept C with four children; CH1 and CH2 each of cardinality of [0..n] and CH3 and CH4 of cardinality of 1. Now I want to have a constraint so that at least one child from CH1 or Ch2 is presented. So this should never happen: 

C-->                 no CH1,                         no CH2,                    one CH3, one CH4             X

but any of the following is acceptable: 

C-->          one (or more) CH1,              no CH2,                    one CH3, one CH4             OR

C-->             no CH1,                    one (or more) CH2,           one CH3, one CH4             OR

C-->          one (or more) CH1,      one (or more) CH2,          one CH3, one CH4

 

I could kind of solve this by adding the following line to the "can be parent" field: 

node.CH1.isNotEmpty || node.CH2.isNotEmpty

but the shown error message says that C cannot be a parent of CH3 and CH4 and that's not the error here. The error should say you should provide at least one instance of CH1 or CH2. 

How should I enforce this constraint?


In general how can I learn about constraints in MPS. All I could find talk about constraints on references but not on children. 


Thank you in advance, 

Amir

 

 

2 comments
Comment actions Permalink

Hi Amir,

I think you should check the Cookbook - Type System (specially the section "Checking and Quick-fixes".

With a Checking rule you can control the errors (or infos) that appear to the user... You can even create a quick fix for the detected problem that can be triggered automatically or by the user.

 

Regards,

Sérgio Ribeiro

Porto - Portugal

 

1
Comment actions Permalink

Hey Sérgio, 

Thanks a a lot. That's exactly what I was looking for.

Cheers, 
Amir

0

Please sign in to leave a comment.