pub(crate) fn parse_statement(
        parser: &mut Parser,
    ) -> Result<ConstrainStatement, ParserErrorKind> {
        parser.advance_tokens();

        let expr = parser.parse_expression(Precedence::Lowest)?;

        // Expressions are eagerly parsed as PredicateStatements before they are parsed as infix
        // We want to convert the outer predicate expression, into an infix expression.
        // It is possible to make this work for predicate statements also,
        // but Predicate statements imply extra constraints, so this should be explicit.
        let infix = match expr.kind.into_infix() {
            Some(infix) => infix,
            None => {
                let message = "Expected an infix expression since this is a constrain statement. You cannot assign values".to_string();
                return Err(ParserErrorKind::UnstructuredError {
                    message,
                    span: expr.span,
                });
            }
        };

        if infix.operator.contents == BinaryOpKind::Assign {
            let message = "Cannot use '=' with a constrain statement".to_string();
            return Err(ParserErrorKind::UnstructuredError {
                message,
                span: infix.operator.span(),
            });
        }

        if disallowed_operators().contains(&infix.operator.contents) {
            let message = format!(
                "Cannot use the {} operator in a constraint statement.",
                infix.operator.contents.as_string()
            );
            return Err(ParserErrorKind::UnstructuredError {
                message,
                span: expr.span,
            });
        }

        // XXX: Add a `help` note to tell the user to add a semi colon here
        parser.peek_check_variant_advance(&Token::Semicolon)?;

        Ok(ConstrainStatement(infix))
    }
// Since == is an infix operator
// The pratt parser will do most of the job, we just need to check that everything was correct
Since == is an infix operator
The pratt parser will do most of the job, we just need to check that everything was correct
Since == is an infix operator The pratt parser will do most of the job we just need to check that everything was correct
pub(crate) fn parse_statement(
        parser: &mut Parser,
    ) -> Result<ConstrainStatement, ParserErrorKind> {
        parser.advance_tokens();
        let expr = parser.parse_expression(Precedence::Lowest)?;
        // Expressions are eagerly parsed as PredicateStatements before they are parsed as infix
        // We want to convert the outer predicate expression, into an infix expression.
        // It is possible to make this work for predicate statements also,
        // but Predicate statements imply extra constraints, so this should be explicit.
        let infix = match expr.kind.into_infix() {
            Some(infix) => infix,
            None => {
                let message = "Expected an infix expression since this is a constrain statement. You cannot assign values".to_string();
                return Err(ParserErrorKind::UnstructuredError {
                    message,
                    span: expr.span,
                });
            }
        };
        if infix.operator.contents == BinaryOpKind::Assign {
            let message = "Cannot use '=' with a constrain statement".to_string();
            return Err(ParserErrorKind::UnstructuredError {
                message,
                span: infix.operator.span(),
            });
        }
        if disallowed_operators().contains(&infix.operator.contents) {
            let message = format!(
                "Cannot use the {} operator in a constraint statement.",
                infix.operator.contents.as_string()
            );
            return Err(ParserErrorKind::UnstructuredError {
                message,
                span: expr.span,
            });
        }
        // XXX: Add a `help` note to tell the user to add a semi colon here
        parser.peek_check_variant_advance(&Token::Semicolon)?;
        Ok(ConstrainStatement(infix))
    }
pub ( crate ) fn parse_statement ( parser : & mut Parser , ) -> Result < ConstrainStatement , ParserErrorKind > { parser . advance_tokens ( ) ; let expr = parser . parse_expression ( Precedence :: Lowest ) ? ; // Expressions are eagerly parsed as PredicateStatements before they are parsed as infix // We want to convert the outer predicate expression, into an infix expression. // It is possible to make this work for predicate statements also, // but Predicate statements imply extra constraints, so this should be explicit. let infix = match expr . kind . into_infix ( ) { Some ( infix ) => infix , None => { let message = " " . to_string ( ) ; return Err ( ParserErrorKind :: UnstructuredError { message , span : expr . span , } ) ; } } ; if infix . operator . contents == BinaryOpKind :: Assign { let message = " " . to_string ( ) ; return Err ( ParserErrorKind :: UnstructuredError { message , span : infix . operator . span ( ) , } ) ; } if disallowed_operators ( ) . contains ( & infix . operator . contents ) { let message = format ! ( " " infix operator contents as_string ( ) ) ; return Err ( ParserErrorKind :: UnstructuredError { message , span : expr . span , } ) ; } // XXX: Add a `help` note to tell the user to add a semi colon here parser . peek_check_variant_advance ( & Token :: Semicolon ) ? ; Ok ( ConstrainStatement ( infix ) ) }
Since == is an infix operator
The pratt parser will do most of the job, we just need to check that everything was correct
Since == is an infix operator The pratt parser will do most of the job we just need to check that everything was correct
parser
&mut Parser
parser
&mut Parser