From 720861bcff4b9f67ca4def66e2996015811fa90b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 Aug 2018 18:16:52 +0300 Subject: Lopps && logical ops --- src/grammar/expressions/atom.rs | 13 +++++++++++++ src/grammar/expressions/mod.rs | 25 ++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/grammar') diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs index 4eb638c3c..65b9e5ef0 100644 --- a/src/grammar/expressions/atom.rs +++ b/src/grammar/expressions/atom.rs @@ -48,6 +48,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option lambda_expr(p), IF_KW => if_expr(p), WHILE_KW => while_expr(p), + LOOP_KW => loop_expr(p), MATCH_KW => match_expr(p), UNSAFE_KW if la == L_CURLY => block_expr(p), L_CURLY => block_expr(p), @@ -143,6 +144,18 @@ fn while_expr(p: &mut Parser) -> CompletedMarker { m.complete(p, WHILE_EXPR) } +// test loop_expr +// fn foo() { +// loop {}; +// } +fn loop_expr(p: &mut Parser) -> CompletedMarker { + assert!(p.at(LOOP_KW)); + let m = p.start(); + p.bump(); + block(p); + m.complete(p, LOOP_EXPR) +} + // test cond // fn foo() { if let Some(_) = None {} } fn cond(p: &mut Parser) { diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index 0312a757a..18e3f5798 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs @@ -56,27 +56,34 @@ enum Op { // x += 1; // 1 + 1 <= 2 * 3; // z -= 3 >= 0; +// true || true && false; // } fn current_op(p: &Parser) -> (u8, Op) { - if p.at_compound2(L_ANGLE, EQ) { - return (3, Op::Composite(LTEQ, 2)); - } - if p.at_compound2(R_ANGLE, EQ) { - return (3, Op::Composite(GTEQ, 2)); - } 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_compound2(PIPE, PIPE) { + return (3, Op::Composite(PIPEPIPE, 2)); + } + if p.at_compound2(AMPERSAND, AMPERSAND) { + return (4, Op::Composite(AMPERSANDAMPERSAND, 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)); + } let bp = match p.current() { EQ => 1, DOTDOT => 2, - EQEQ | NEQ => 3, - MINUS | PLUS => 4, - STAR | SLASH => 5, + EQEQ | NEQ => 5, + MINUS | PLUS => 6, + STAR | SLASH => 7, _ => 0, }; (bp, Op::Simple) -- cgit v1.2.3