From be4e54c5be1344d631f5b8921cbc2392d5e3a757 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Tue, 13 Sep 2022 20:46:16 +0100 Subject: [PATCH] parser: add associativity mappings --- trunk_parser/src/parser/precedence.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/trunk_parser/src/parser/precedence.rs b/trunk_parser/src/parser/precedence.rs index ed6ed41..4b21d3f 100644 --- a/trunk_parser/src/parser/precedence.rs +++ b/trunk_parser/src/parser/precedence.rs @@ -81,10 +81,31 @@ impl Precedence { _ => unimplemented!("postfix precedence for op {:?}", kind), } } + + pub fn associativity(&self) -> Option { + 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, }