[Parser]
Disallow a list of operators to be used in the middle of a constrain statement.
Only predicate operators for now, later on we will decide what to do when it is not a predicate op.
@@ -7,6 +7,16 @@ use librasac_ast::ConstrainStatement;
/// Possibly could have an invariant for these types of Statements, so that the evaluator can be less complex
pub struct ConstraintParser;
+// XXX: For now we disallow statement of the form `constrain x / y` as their meaning is a bit ambiguous
+// In the future, if there is a disallowed operator, we will modify the AST so that it's RHS is zero
+// We will also do it for the other expressions
+// Example1 `constrain x` becomes `constrain x == 0`
+// Example2 `constrain x / y` becomes `constrain x/y == 0`
+// XXX: However, I'm wondering if we should avoid doing anything under the hood and just have users explicitly writing what they mean?
+fn disallowed_operators() -> Vec<BinaryOp> {
+ vec![BinaryOp::And, BinaryOp::Or, BinaryOp::Divide,BinaryOp::Multiply]
+}
+
impl ConstraintParser {
// Since == is an infix operator
// The pratt parser will do most of the job, we just need to check that everything was correct
@@ -23,8 +33,8 @@ impl ConstraintParser {
panic!("Cannot use '=' with a constrain statement")
}
- if (infix.operator == BinaryOp::And) || (infix.operator == BinaryOp::Or) {
- panic!("Cannot use the & or | operator in a constraint statement. Currently, it has not been decided how they will be implemented\n Maybe they will be implemented only for bit strings? TBD")
+ if disallowed_operators().contains(&infix.operator) {
+ panic!("Cannot use the {:?} operator in a constraint statement." , &infix.operator)
}
let stmt = ConstrainStatement(infix);
