From cf7d4a2a243cac1975b9b28d47ed91a6bd01b34f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Aug 2018 00:48:10 +0300 Subject: Simplify --- crates/libsyntax2/src/grammar/expressions/mod.rs | 54 ++++++++++++------------ 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'crates/libsyntax2/src/grammar') diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs index feef5f1d6..3da539699 100644 --- a/crates/libsyntax2/src/grammar/expressions/mod.rs +++ b/crates/libsyntax2/src/grammar/expressions/mod.rs @@ -45,35 +45,33 @@ enum Op { } fn current_op(p: &Parser) -> (u8, Op) { - if p.at_compound2(PLUS, EQ) { - return (1, Op::Composite(PLUSEQ, 2)); - } - if p.at_compound2(MINUS, EQ) { - return (1, Op::Composite(MINUSEQ, 2)); - } - if p.at_compound3(L_ANGLE, L_ANGLE, EQ) { - return (1, Op::Composite(SHLEQ, 3)); - } - if p.at_compound3(R_ANGLE, R_ANGLE, EQ) { - return (1, Op::Composite(SHREQ, 3)); - } - if p.at_compound2(PIPE, PIPE) { - return (3, Op::Composite(PIPEPIPE, 2)); - } - if p.at_compound2(AMP, AMP) { - return (4, Op::Composite(AMPAMP, 2)); - } - if p.at_compound2(L_ANGLE, EQ) { - return (5, Op::Composite(LTEQ, 2)); - } - if p.at_compound2(R_ANGLE, EQ) { - return (5, Op::Composite(GTEQ, 2)); - } - if p.at_compound2(L_ANGLE, L_ANGLE) { - return (9, Op::Composite(SHL, 2)); + if let Some(t) = p.next3() { + match t { + (L_ANGLE, L_ANGLE, EQ) => + return (1, Op::Composite(SHLEQ, 3)), + (R_ANGLE, R_ANGLE, EQ) => + return (1, Op::Composite(SHREQ, 3)), + _ => (), + } } - if p.at_compound2(R_ANGLE, R_ANGLE) { - return (9, Op::Composite(SHR, 2)); + + if let Some(t) = p.next2() { + match t { + (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), + (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), + (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)), + (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)), + (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)), + (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)), + (CARET, EQ) => return (1, Op::Composite(CARETEQ, 2)), + (PIPE, PIPE) => return (3, Op::Composite(PIPEPIPE, 2)), + (AMP, AMP) => return (4, Op::Composite(AMPAMP, 2)), + (L_ANGLE, EQ) => return (5, Op::Composite(LTEQ, 2)), + (R_ANGLE, EQ) => return (5, Op::Composite(GTEQ, 2)), + (L_ANGLE, L_ANGLE) => return (9, Op::Composite(SHL, 2)), + (R_ANGLE, R_ANGLE) => return (9, Op::Composite(SHR, 2)), + _ => (), + } } let bp = match p.current() { -- cgit v1.2.3