modification to pretty printing for constants and nesting
This commit is contained in:
parent
672c7037f6
commit
d18ac475d1
|
@ -5,6 +5,7 @@ use crate::ast::{Constant, Name, Program, Term};
|
||||||
impl Program<Name> {
|
impl Program<Name> {
|
||||||
pub fn to_pretty(&self) -> String {
|
pub fn to_pretty(&self) -> String {
|
||||||
let mut w = Vec::new();
|
let mut w = Vec::new();
|
||||||
|
println!("here");
|
||||||
|
|
||||||
self.to_doc().render(100, &mut w).unwrap();
|
self.to_doc().render(100, &mut w).unwrap();
|
||||||
|
|
||||||
|
@ -17,9 +18,10 @@ impl Program<Name> {
|
||||||
RcDoc::text("(")
|
RcDoc::text("(")
|
||||||
.append(RcDoc::text("program"))
|
.append(RcDoc::text("program"))
|
||||||
.append(RcDoc::line())
|
.append(RcDoc::line())
|
||||||
.append(RcDoc::text(version).nest(2))
|
.append(RcDoc::text(version))
|
||||||
.append(RcDoc::line())
|
.append(RcDoc::line())
|
||||||
.append(self.term.to_doc())
|
.append(self.term.to_doc())
|
||||||
|
.nest(2)
|
||||||
.append(RcDoc::line_())
|
.append(RcDoc::line_())
|
||||||
.append(RcDoc::text(")"))
|
.append(RcDoc::text(")"))
|
||||||
}
|
}
|
||||||
|
@ -62,8 +64,9 @@ impl Term<Name> {
|
||||||
.append(RcDoc::text("]")),
|
.append(RcDoc::text("]")),
|
||||||
Term::Constant(constant) => RcDoc::text("(")
|
Term::Constant(constant) => RcDoc::text("(")
|
||||||
.append(RcDoc::text("con"))
|
.append(RcDoc::text("con"))
|
||||||
.append(RcDoc::text(" "))
|
.append(RcDoc::line())
|
||||||
.append(constant.to_doc())
|
.append(constant.to_doc())
|
||||||
|
.append(RcDoc::line_())
|
||||||
.append(RcDoc::text(")")),
|
.append(RcDoc::text(")")),
|
||||||
Term::Force(term) => RcDoc::text("(")
|
Term::Force(term) => RcDoc::text("(")
|
||||||
.append(RcDoc::text("force"))
|
.append(RcDoc::text("force"))
|
||||||
|
@ -82,6 +85,7 @@ impl Term<Name> {
|
||||||
.append(RcDoc::text(")")),
|
.append(RcDoc::text(")")),
|
||||||
}
|
}
|
||||||
.nest(2)
|
.nest(2)
|
||||||
|
.group()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,20 +93,23 @@ impl Constant {
|
||||||
fn to_doc(&self) -> RcDoc<()> {
|
fn to_doc(&self) -> RcDoc<()> {
|
||||||
match self {
|
match self {
|
||||||
Constant::Integer(i) => RcDoc::text("integer")
|
Constant::Integer(i) => RcDoc::text("integer")
|
||||||
.append(RcDoc::space())
|
.append(RcDoc::line())
|
||||||
.append(RcDoc::as_string(i)),
|
.append(RcDoc::as_string(i)),
|
||||||
Constant::ByteString(bs) => RcDoc::text("bytestring")
|
Constant::ByteString(bs) => RcDoc::text("bytestring")
|
||||||
.append(RcDoc::space())
|
.append(RcDoc::line())
|
||||||
|
.append(RcDoc::text("#"))
|
||||||
.append(RcDoc::text(hex::encode(bs))),
|
.append(RcDoc::text(hex::encode(bs))),
|
||||||
Constant::String(s) => RcDoc::text("string")
|
Constant::String(s) => RcDoc::text("string")
|
||||||
.append(RcDoc::space())
|
.append(RcDoc::line())
|
||||||
.append(RcDoc::text(s)),
|
.append(RcDoc::text("\""))
|
||||||
|
.append(RcDoc::text(s))
|
||||||
|
.append(RcDoc::text("\"")),
|
||||||
Constant::Char(c) => unimplemented!("char: {}", c),
|
Constant::Char(c) => unimplemented!("char: {}", c),
|
||||||
Constant::Unit => RcDoc::text("unit")
|
Constant::Unit => RcDoc::text("unit")
|
||||||
.append(RcDoc::space())
|
.append(RcDoc::line())
|
||||||
.append(RcDoc::text("()")),
|
.append(RcDoc::text("()")),
|
||||||
Constant::Bool(b) => RcDoc::text("bool")
|
Constant::Bool(b) => RcDoc::text("bool")
|
||||||
.append(RcDoc::space())
|
.append(RcDoc::line())
|
||||||
.append(RcDoc::text(if *b { "true" } else { "false" })),
|
.append(RcDoc::text(if *b { "true" } else { "false" })),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue