From 6759640389a5649971695a26083a6ae733ec93db Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 13 Feb 2020 02:57:30 -0800 Subject: [PATCH] Fix whitespace --- schala-lang/language/src/parser.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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,