The Validator flag provides special behavior.
If a rule "Rule1" is present, and a rule flagged "Validator" Rule1 is present, then the Validator provides validation and / or filtering of the results of Rule1.
The rule with the Validator flag is said to be the validator rule. The other rule by the same name is the target rule. When the target rule is referenced, if not already bound, then the validator is evaluated instead. During the validator's evaluation, it would (normally, but not required) obtain the pre-validated value of the target rule, process it in whatever way it wants, and return the result as the value of the target rule. The validator rule is never cached, and never directly referenced. In the case of the target rule name being Rule1, the validator rule is internally rewritten to be a Method with Rule1_%%vtor.
Any external reference to Rule1 obtains the value as returned by Rule1_%%vtor. Within Rule1_%%vtor, any reference to Rule1 obtains the value it would have without a validator present (the raw value). So the writer of the validator rule is free to inspect the raw value and modify or replace it or generate an error based on it.
The target rule and validator rule must have the same data type, or an exception is thrown.
Target rules can have any normal rule flags, but cannot be any of the special rule types, such as Child , Group , or Method . The behavior with respect to Lookup and other defaults is that the validator runs "last", after any other behaviors are applied. So a value obtained from Lookup will be validated.
Validator rules ignore all flags, other than Validator.
Validators which exist but have no matching base rule will not be evaluated. Warnings may be issued during compilation.
Validator rules may not be Dynamic rules. However, the target rule may be Dynamic.
Validators and target rules must exist on the same Design (or Part, if dynamic). They will not "lookup" for matches.
Consider the following Intent source code:
'! Intent Language(tm) 3.0 Design Validator : BasePart Parameter Rule Ex1 As Integer = 42 Validator Rule Ex1 As Integer If (Ex1 < 0) Then Return 0 Else If (Ex1 > 100) Then Return 100 End If Return Ex1 End Rule End Design
No matter what Integer is supplied to Ex1, it will return a value between 0 and 100 inclusive.
For testing, it is legal to call Ex1_%%vtor as a method. It will return its single argument validated.
It is circular to reference Ex1 indirectly in Validator Ex1. For example, if Ex2 referenced Ex1, and Ex1_validator referenced Ex2, a circular reference would be detected. This is because Ex2 can only access Ex1 after validation, but that validation is being evaluated at the time of the call.