FEATURE: Comparison binary expressions now support non-compare expressions on both sides.

This commit is contained in:
Jeremy Wall 2018-06-06 21:02:02 -05:00
parent 3d7c70aa2a
commit 3524a5df73
2 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,4 @@
use super::Builder;
use std;
fn assert_build(input: &str) {
let mut b = Builder::new("<Eval>");
@ -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]

View File

@ -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