From 3524a5df736ce3ca80e31afd13e88bfd55e75cb5 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 6 Jun 2018 21:02:02 -0500 Subject: [PATCH] FEATURE: Comparison binary expressions now support non-compare expressions on both sides. --- src/build/compile_test.rs | 16 +++++++++------- src/parse/mod.rs | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index c714d07..2947d54 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -1,5 +1,4 @@ use super::Builder; -use std; fn assert_build(input: &str) { let mut b = Builder::new(""); @@ -13,8 +12,7 @@ fn assert_build(input: &str) { #[test] fn test_comparisons() { assert_build( - " - let one = 1; + "let one = 1; let two = 2; let foo = \"foo\"; let bar = \"bar\"; @@ -45,8 +43,8 @@ fn test_comparisons() { #[test] fn test_deep_comparison() { - let input = " - let tpl1 = { + assert_build( + "let tpl1 = { foo = \"bar\", lst = [1, 2, 3], inner = { @@ -65,8 +63,8 @@ fn test_deep_comparison() { assert \"tpl1 == copy\"; assert \"tpl1 != extra\"; assert \"tpl1 != less\"; - "; - assert_build(input); + ", + ); } #[test] @@ -74,6 +72,10 @@ fn test_expression_comparisons() { assert_build("assert \"2 == 1+1\";"); assert_build("assert \"(1+1) == 2\";"); assert_build("assert \"(1+1) == (1+1)\";"); + assert_build( + "let want = \"foo\"; + assert \"select want, 1, { foo=2, } == 2\";", + ); } #[test] diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 005d6d5..099bf27 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -386,14 +386,16 @@ fn tuple_to_compare_expression( })) } +// This macro is much simpler than the math binary expressions since they are the +// bottom of the precendence tree and we can hard code the precedence in here. macro_rules! do_compare_expr { ($i:expr, $subrule:ident!( $($args:tt)* ), $typ:expr) => { map_res!($i, do_parse!( pos: pos >> - left: alt!(simple_expression | grouped_expression | math_expression) >> + left: alt!(math_expression | non_op_expression) >> $subrule!($($args)*) >> - right: expression >> + right: alt!(math_expression | non_op_expression) >> (pos, $typ, left, right) ), tuple_to_compare_expression