diff --git a/src/parser.rs b/src/parser.rs index c038c3d..cfa916c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,17 +1,12 @@ use nom::{ branch::alt, - bytes::complete::{escaped, is_not}, - bytes::complete::{tag, take_until}, - character::complete::char, - character::complete::multispace0, - character::complete::{alpha1, alphanumeric1, digit1, one_of, space0}, - combinator::value, - combinator::{cut, map, map_res, recognize}, - error::{context, convert_error, ContextError, ErrorKind, ParseError, VerboseError}, + bytes::complete::{escaped, is_not, tag, take_until}, + character::complete::{alpha1, alphanumeric1, char, multispace0, one_of, space0}, + combinator::{cut, map, recognize, value}, + error::ParseError, multi::{fold_many0, many0, separated_list0}, number::complete::double, - sequence::pair, - sequence::{delimited, preceded, terminated, tuple}, + sequence::{delimited, pair, preceded, terminated, tuple}, IResult, Parser, }; @@ -28,17 +23,11 @@ fn pinline_comment<'a, E>(i: &'a str) -> IResult<&'a str, (), E> where E: ParseError<&'a str>, { - value( - (), // Output is thrown away. - tuple((tag("/*"), take_until("*/"), tag("*/"))), - )(i) + value((), tuple((tag("/*"), take_until("*/"), tag("*/"))))(i) } fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> { - value( - (), // Output is thrown away. - pair(char('/'), is_not("\n\r")), - )(i) + value((), pair(char('/'), is_not("\n\r")))(i) } fn braces<'a, P, O, E>(a: P) -> impl FnMut(&'a str) -> IResult<&'a str, O, E> @@ -145,13 +134,13 @@ fn bin_equal_not(i: &str) -> IResult<&str, Expr> { let (i, init) = bin_less_greater(i)?; fold_many0( - pair(alt((char('<'), char('>'))), bin_less_greater), + pair(alt((tag("=="), tag("!="))), bin_less_greater), move || init.clone(), - |acc, (op, val): (char, Expr)| { - if op == '<' { - Expr::Binary(BinOp::LessThan, Box::new(acc), Box::new(val)) + |acc, (op, val)| { + if op == "==" { + Expr::Binary(BinOp::Equals, Box::new(acc), Box::new(val)) } else { - Expr::Binary(BinOp::GreaterThan, Box::new(acc), Box::new(val)) + Expr::Binary(BinOp::NotEquals, Box::new(acc), Box::new(val)) } }, )(i)