Fix whitespace
This commit is contained in:
parent
c6b0f7d7d1
commit
6759640389
@ -4,7 +4,7 @@ use std::rc::Rc;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use nom::IResult;
|
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::bytes::complete::{tag, take_while};
|
||||||
use nom::combinator::{map, map_res, value, opt};
|
use nom::combinator::{map, map_res, value, opt};
|
||||||
use nom::multi::many1;
|
use nom::multi::many1;
|
||||||
@ -115,7 +115,9 @@ fn prefix_op(input: &str) -> IResult<&str, PrefixOp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prefix_expr(input: &str) -> IResult<&str, ExpressionKind> {
|
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((
|
let (rest, result) = alt((
|
||||||
paren_expr,
|
paren_expr,
|
||||||
parse_literal
|
parse_literal
|
||||||
@ -133,17 +135,17 @@ fn prefix_expr(input: &str) -> IResult<&str, ExpressionKind> {
|
|||||||
fn precedence_expr(input: &str, precedence: i32) -> IResult<&str, ExpressionKind> {
|
fn precedence_expr(input: &str, precedence: i32) -> IResult<&str, ExpressionKind> {
|
||||||
let (mut outer_rest, mut lhs) = prefix_expr(input)?;
|
let (mut outer_rest, mut lhs) = prefix_expr(input)?;
|
||||||
loop {
|
loop {
|
||||||
let (rest, maybe_binop) = opt(parse_binop)(outer_rest)?;
|
let (rest, _) = space0(outer_rest)?;
|
||||||
println!("REST: {} | and maybe: {:?}", rest, maybe_binop);
|
let (rest, maybe_binop) = opt(parse_binop)(rest)?;
|
||||||
let (new_precedence, binop) = match maybe_binop {
|
let (new_precedence, binop) = match maybe_binop {
|
||||||
Some(binop) => (binop.precedence(), binop),
|
Some(binop) => (binop.precedence(), binop),
|
||||||
None => break,
|
None => break,
|
||||||
};
|
};
|
||||||
println!("Calculated new precedence: {} for binop: {:?}", new_precedence, binop);
|
|
||||||
|
|
||||||
if precedence >= new_precedence {
|
if precedence >= new_precedence {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let (rest, _) = space0(rest)?;
|
||||||
let (rest, rhs) = precedence_expr(rest, new_precedence)?;
|
let (rest, rhs) = precedence_expr(rest, new_precedence)?;
|
||||||
outer_rest = rest;
|
outer_rest = rest;
|
||||||
lhs = ExpressionKind::BinExp(binop,
|
lhs = ExpressionKind::BinExp(binop,
|
||||||
|
Loading…
Reference in New Issue
Block a user