Guys i need some help i spent several days stuck over this it should be really simple it's just that i'm dumb so here i have a parser file called parser.rs in it i have created this function that only parses binary comparisons
pub fn comparison(input: &str) -> IResult<&str, Node> {
let (input, left) = value(input)?;
let (input, _) = many0(tag(" "))(input)?;
let (input, operator) = alt((
tag("=="), tag("!="), tag("<="), tag(">="), tag("<"), tag(">")
))(input)?;
let (input, _) = many0(tag(" "))(input)?;
let (input, right) = value(input)?;
let children = vec![left, right];
let name = match operator {
"==" => "==",
"!=" => "!=",
"<=" => "<=",
">=" => ">=",
"<" => "<",
">" => ">",
_ => return Err(nom::Err::Failure(nom::error::Error::new(input, nom::error::ErrorKind::Tag)))
};
Ok((input, Node::ComparisonExpression { name: name.to_string(), children }))
}
this is what it looks like as you can see it's failing to pass this test test!(invalidComparison2, r#"x + y * z > x * y - z == false"#, Ok(Value::Bool(true)));
giving me this error "
---- invalidComparison2 stdout ----
thread 'invalidComparison2' panicked at 'assertion failed: (left == right)
left: " > x * y - z == false",
right: ""', tests\test.rs:78:1
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
failures:
invalidComparison2
test result: FAILED. 34 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.09s
error: test failed, to rerun pass --test test" so what i want to know is how can i please make this function handle all type of comparisons and be able to parse them correctly .Thanks in advance