parser: add associativity mappings

This commit is contained in:
Ryan Chandler 2022-09-13 20:46:16 +01:00
parent f4de25d2dc
commit be4e54c5be
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -81,10 +81,31 @@ impl Precedence {
_ => unimplemented!("postfix precedence for op {:?}", kind),
}
}
pub fn associativity(&self) -> Option<Associativity> {
Some(match self {
Self::Instanceof
| Self::MulDivMod
| Self::AddSub
| Self::BitShift
| Self::Concat
| Self::BitwiseAnd
| Self::BitwiseOr
| Self::BitwiseXor
| Self::And
| Self::Or
| Self::KeyAnd
| Self::KeyOr
| Self::KeyXor => Associativity::Left,
Self::Pow | Self::NullCoalesce | Self::Assignment => Associativity::Right,
Self::Ternary | Self::Equality | Self::LtGt => Associativity::Non,
_ => return None,
})
}
}
pub enum Associativity {
None,
Non,
Left,
Right,
}