Skip to content
Snippets Groups Projects
Commit dc365160 authored by Per Lindgren's avatar Per Lindgren
Browse files

move to new syntax, wip7 broken

parent 2bb6b324
No related branches found
No related tags found
No related merge requests found
fn main() { fn main() {
// {} {}
let mut a = 5; let mut a = 5;
a = 5; a = 5;
// a = { 7 } a = { 7 };
a = if true { 7 } else { 5 }
} }
fn b(x: i32) -> i32 { fn b(x: i32) -> i32 {
......
...@@ -218,10 +218,18 @@ impl Stmts { ...@@ -218,10 +218,18 @@ impl Stmts {
// set tab // set tab
write!(fmt, "\n{}", " ".repeat(indent + 4))?; write!(fmt, "\n{}", " ".repeat(indent + 4))?;
s.ifmt(fmt, indent + 4)?; s.ifmt(fmt, indent + 4)?;
if i < len - 1 || self.ret {
if i < len - 1 {
match s {
Stmt::Block(_) | Stmt::If(_, _, _) => (),
_ => write!(fmt, ";")?,
}
} else {
if self.ret {
write!(fmt, ";")?; write!(fmt, ";")?;
} }
} }
}
write!(fmt, "\n{}}}", " ".repeat(indent)) write!(fmt, "\n{}}}", " ".repeat(indent))
} }
} }
...@@ -305,6 +313,7 @@ impl Display for Type { ...@@ -305,6 +313,7 @@ impl Display for Type {
} }
} }
} }
impl Display for Expr { impl Display for Expr {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
use self::Expr::*; use self::Expr::*;
...@@ -325,6 +334,26 @@ impl Display for Expr { ...@@ -325,6 +334,26 @@ impl Display for Expr {
} }
} }
impl Expr {
fn ifmt(&self, fmt: &mut Formatter, indent: i32) -> Result<(), Error> {
use self::Expr::*;
match *self {
Num(n) => write!(fmt, "{}", n),
Bool(b) => write!(fmt, "{}", b),
Id(ref s) => write!(fmt, "{}", s),
As(ref e, ref t) => write!(fmt, "{} as {}", e, t),
Infix(ref l, ref op, ref r) => write!(fmt, "({} {} {})", l, op, r),
Prefix(ref op, ref r) => write!(fmt, "({} {})", op, r),
Ref(ref e) => write!(fmt, "&{}", e),
RefMut(ref e) => write!(fmt, "&mut {}", e),
DeRef(ref e) => write!(fmt, "*{}", e),
Call(ref s, ref exprs) => write!(fmt, "{}{}", s, exprs),
Block(ref s) => write!(fmt, "{}", s),
Stmt(ref s) => write!(fmt, "{}", s),
}
}
}
impl Display for Op { impl Display for Op {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
use self::Op::*; use self::Op::*;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment