Skip to main content

prefix_operand_needs_parens

Function prefix_operand_needs_parens 

Source
fn prefix_operand_needs_parens<T: AstInfo>(operand: &Expr<T>) -> bool
Expand description

Whether the operand of a prefix operator (-/+/~) must be parenthesized to round-trip. A prefix op binds tighter than COLLATE/AT TIME ZONE and the binary/comparison operators, but looser than the postfix ::/[…] forms — and - <number> additionally lexes as a negative literal. So peel the tight postfixes (::/[…]); if the chain bottoms out at a numeric literal the sign would fold into it, and if it bottoms out at anything other than a self-delimiting non-COLLATE primary (a COLLATE, a binary op, …) the prefix op would re-associate — both need parens. (a + b COLLATE c reparses as a + (b COLLATE c); - x COLLATE c as (- x) COLLATE c.)