Feat: add compound assignment and shift operators
Compound assignment: +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= Shift: <<, >> Each compound assignment token parses at the same precedence as `=` (right-associative, lowest) and produces ExprKind::CompoundAssign. Shifts parse between additive and multiplicative precedence. GRAMMAR.ebnf and SYNTAX.md updated accordingly.
This commit is contained in:
@@ -11,6 +11,20 @@ pub enum UnaryOp {
|
||||
AddrOf, // `&`
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CompoundAssignOp {
|
||||
Add, // `+=`
|
||||
Sub, // `-=`
|
||||
Mul, // `*=`
|
||||
Div, // `/=`
|
||||
Rem, // `%=`
|
||||
BitAnd, // `&=`
|
||||
BitOr, // `|=`
|
||||
BitXor, // `^=`
|
||||
Shl, // `<<=`
|
||||
Shr, // `>>=`
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BinaryOp {
|
||||
// Logical
|
||||
@@ -33,6 +47,9 @@ pub enum BinaryOp {
|
||||
Mul, // `*`
|
||||
Div, // `/`
|
||||
Rem, // `%`
|
||||
// Shift
|
||||
Shl, // `<<`
|
||||
Shr, // `>>`
|
||||
// Assignment (lowest precedence, right-associative)
|
||||
Assign, // `=`
|
||||
}
|
||||
@@ -123,6 +140,13 @@ pub enum ExprKind {
|
||||
lhs: Box<Expr>,
|
||||
rhs: Box<Expr>,
|
||||
},
|
||||
// Compound assignment: `lhs op= rhs` (expands to `lhs = lhs op rhs`)
|
||||
CompoundAssign {
|
||||
op: CompoundAssignOp,
|
||||
op_span: Span,
|
||||
lhs: Box<Expr>,
|
||||
rhs: Box<Expr>,
|
||||
},
|
||||
|
||||
// Postfix
|
||||
Field {
|
||||
|
||||
Reference in New Issue
Block a user