diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 5dac49b..12fb4cd 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use std::str::FromStr; use nom::IResult; -use nom::character::complete::{one_of}; +use nom::character::complete::{one_of, space0}; use nom::bytes::complete::{tag, take_while}; use nom::combinator::{map, map_res, value, opt}; use nom::multi::many1; @@ -115,7 +115,9 @@ fn prefix_op(input: &str) -> IResult<&str, PrefixOp> { } fn prefix_expr(input: &str) -> IResult<&str, ExpressionKind> { - let (rest, pfx) = opt(prefix_op)(input)?; + let (rest, _) = space0(input)?; + let (rest, pfx) = opt(prefix_op)(rest)?; + let (rest, _) = space0(rest)?; let (rest, result) = alt(( paren_expr, parse_literal @@ -133,17 +135,17 @@ fn prefix_expr(input: &str) -> IResult<&str, ExpressionKind> { fn precedence_expr(input: &str, precedence: i32) -> IResult<&str, ExpressionKind> { let (mut outer_rest, mut lhs) = prefix_expr(input)?; loop { - let (rest, maybe_binop) = opt(parse_binop)(outer_rest)?; - println!("REST: {} | and maybe: {:?}", rest, maybe_binop); + let (rest, _) = space0(outer_rest)?; + let (rest, maybe_binop) = opt(parse_binop)(rest)?; let (new_precedence, binop) = match maybe_binop { Some(binop) => (binop.precedence(), binop), None => break, }; - println!("Calculated new precedence: {} for binop: {:?}", new_precedence, binop); if precedence >= new_precedence { break; } + let (rest, _) = space0(rest)?; let (rest, rhs) = precedence_expr(rest, new_precedence)?; outer_rest = rest; lhs = ExpressionKind::BinExp(binop,