Fix whitespace

This commit is contained in:
greg 2020-02-13 02:57:30 -08:00
parent c6b0f7d7d1
commit 6759640389

View File

@ -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,