From 6145cb5a4878b711b075da3759c2c60307fb43b2 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 4 Sep 2017 20:31:28 +0200 Subject: Clean up and tighten faster version of expr_prec_layer macro --- askama_shared/src/parser.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 8ff2063..1156b68 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -229,21 +229,16 @@ named!(expr_filtered, do_parse!( macro_rules! expr_prec_layer { ( $name:ident, $inner:ident, $( $op:expr ),* ) => { - named!($name, - do_parse!( - left: $inner >> - op_and_right: opt!(pair!(ws!(alt!($( tag_s!($op) )|*)), expr_any)) >> - ( - if op_and_right.is_some() { - let (op, right) = op_and_right.unwrap(); - (Expr::BinOp(str::from_utf8(op).unwrap(), - Box::new(left), Box::new(right))) - } else { - left - } - ) - ) - ); + named!($name, do_parse!( + left: $inner >> + op_and_right: opt!(pair!(ws!(alt!($( tag_s!($op) )|*)), expr_any)) >> + (match op_and_right { + Some((op, right)) => Expr::BinOp( + str::from_utf8(op).unwrap(), Box::new(left), Box::new(right) + ), + None => left, + }) + )); } } -- cgit