Closed mnapoli closed 8 years ago
What I did for now and that seems to work:
try {
$this->rulerzCompiler->compile($rules, new ArrayVisitor);
} catch (UnexpectedToken $e) {
throw new InvalidRules('Invalid promotion rules: ' . $rules, 0, $e);
}
Is there a way to "test" that some rules are valid?
To consider a rule as "valid", it must:
I've already implemented these verifications in wallabag to check that the tagging rules written by users are valid.
I've written a RuleValidator
that compiles the rule, and I use the resulting model to check that all the used variables and operators are allowed. As there is no way to automatically know which variables and operators are allowed, I used a whitelist.
@mnapoli do you need additional input on this?
Nope thanks, we've used the trick I shown above for now.
When a UI is responsible for generating some rules, we need to make sure they are valid (that they will execute correctly). Is there a way to "test" that some rules are valid?
What I thought of is trying to compile them with the compiler that Rulerz uses, but:
$compiler->compile($rule, $targetCompiler)
can I simply useArrayVisitor
(most basic one) or do I need to set up something more complex?And finally would it make sense to add that to Rulerz directly?