From 21c98d6364597c44fe40acc7c8ef51a2daf5ac6f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 11 Jul 2019 22:03:48 -0400 Subject: [PATCH] Parse && and || --- src/parse.rs | 2 ++ tests/test_parse.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/parse.rs b/src/parse.rs index 62818e2fb8..aa91482d83 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -404,10 +404,12 @@ where I: Stream, I::Error: ParseError { choice(( + string("&&").map(|_| Operator::And), attempt(string("==")).map(|_| Operator::Equals), attempt(string("<=")).map(|_| Operator::LessThanOrEq), attempt(string(">=")).map(|_| Operator::GreaterThanOrEq), attempt(string("|>")).map(|_| Operator::Pizza), + string("||").map(|_| Operator::Or), char('+').map(|_| Operator::Plus), char('-').map(|_| Operator::Minus), char('*').map(|_| Operator::Star), diff --git a/tests/test_parse.rs b/tests/test_parse.rs index 37f9f0d6a7..960aedcd25 100644 --- a/tests/test_parse.rs +++ b/tests/test_parse.rs @@ -1392,4 +1392,23 @@ mod test_parse { "")) ); } + + #[test] + fn compare_and() { + assert_eq!( + parse_with_precedence("x > 1 || True"), + Ok((Operator( + loc_box( + Operator( + loc_box(Var("x".to_string())), + loc(GreaterThan), + loc_box(Int(1)) + ) + ), + loc(Or), + loc_box(ApplyVariant("True".to_string(), None)) + ), + "")) + ); + } }