Constraint Rules
The Constraints Language suffers from several deficiencies, like the inability to specify error messages for individual constraints or the inability to define multiple separate rules for the same kind of constraint. The experimental Constraint Rules language attempts to overcome those. It is available in the Constraints aspect under the RulesConstraintsRules root:
Can be child/parent/ancestor/root rules
The RulesConstraintsRules root chooses a minimalistic visual guidance:
The definition is split into Rules blocks. Each of these rules blocks must be dedicated to one of four possible categories:
CanBeAncestor
CanBeChild
CanBeParent
CanBeRoot
Each Rules block contains members of two types:
Variable definition - a reusable pre-calculated value that can be used in rules
Rule definition - a logical expression to evaluate as a constraint, with optional name for easy reference (e.g. from tests), an optional error message and an optional Applicability guard expression.
Implicit parameters of rules blocks
Each Rules block receive parameters that capture the context for evaluation in rules. These are available in the completion menu:
These parameters can also be used to form the rule's error messages:
Each kind of rules block offers a different set of implicit parameters:
CanBeRoot - concept, model
CanBeChild - childNode, parentNode, link
CanBeParent - childNode, parentNode, link, childConcept
CanBeAncestor - ancestorNode, parentNode, descendantNode, descendantConcept, link
Tracing constraint rules evaluation
The constraint rules definitions allow logging messages to be specified in the Inspector window for better tracing:
You can use a single log statement or a BlockStatement to include a more complex logic.
Specify the feature to highlight
The error message for a constraint rule can be targeted for specific node’s properties or references.
Instead of the error highlighting the whole node, it can be configured to only highlight a property or a reference:
The feature to highlight property may be set to restrict the error highlighting:
You can either refer to a property of a reference directly or by using an expression: