Skip to content

Commit

Permalink
[ pretty ] Further improve pretty.rs, bump version to 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Sep 13, 2019
1 parent f35f6b6 commit fd8d9c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

# 0.4.1

+ Improve `pretty.rs` by using the `write!` macro
+ Generate `Unit` when the type is `One` (#25)
+ Sync katex-header.html changes from Voile

# 0.4.0

+ Documentation update
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "minitt"
version = "0.4.0"
version = "0.4.1"
authors = ["ice1000 <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
59 changes: 10 additions & 49 deletions src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,9 @@ impl Display for Expression {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
match self {
Expression::Var(name) => name.fmt(f),
Expression::First(pair) => {
f.write_char('(')?;
pair.fmt(f)?;
f.write_str(".1")?;
f.write_char(')')
}
Expression::Second(pair) => {
f.write_char('(')?;
pair.fmt(f)?;
f.write_str(".2")?;
f.write_char(')')
}
Expression::Application(function, argument) => {
f.write_char('(')?;
function.fmt(f)?;
f.write_char(' ')?;
argument.fmt(f)?;
f.write_char(')')
}
Expression::First(pair) => write!(f, "({}.1)", pair),
Expression::Second(pair) => write!(f, "({}.2)", pair),
Expression::Application(function, argument) => write!(f, "({} {})", function, argument),
Expression::Lambda(pattern, parameter_type, body) => {
f.write_str("\u{03BB} ")?;
pattern.fmt(f)?;
Expand All @@ -76,38 +60,19 @@ impl Display for Expression {
f.write_str(". ")?;
body.fmt(f)
}
Expression::Pair(first, second) => {
f.write_char('(')?;
first.fmt(f)?;
f.write_str(", ")?;
second.fmt(f)?;
f.write_char(')')
}
Expression::Pair(first, second) => write!(f, "({}, {})", first, second),
Expression::Unit => f.write_str("0"),
Expression::One => f.write_str("1"),
Expression::Pi(input, output) => {
f.write_str("\u{03A0}")?;
f.write_str(" ")?;
input.fmt(f)?;
f.write_str(". ")?;
output.fmt(f)
}
Expression::Type(level) => {
f.write_str("Type")?;
level.fmt(f)
write!(f, " {}. {}", input, output)
}
Expression::Type(level) => write!(f, "Type{}", level),
Expression::Sigma(first, second) => {
f.write_str("\u{03A3}")?;
f.write_str(" ")?;
first.fmt(f)?;
f.write_str(". ")?;
second.fmt(f)
}
Expression::Constructor(name, arguments) => {
name.fmt(f)?;
f.write_str(" ")?;
arguments.fmt(f)
write!(f, " {}. {}", first, second)
}
Expression::Constructor(name, arguments) => write!(f, "{} {}", name, arguments),
Expression::Split(clauses) => {
f.write_str("split {")?;
let mut started = false;
Expand Down Expand Up @@ -242,9 +207,7 @@ impl<Value: Display + Clone> Display for GenericNeutral<Value> {
GenericNeutral::First(pair) => write!(f, "({}.1)", pair),
GenericNeutral::Second(pair) => write!(f, "({}.2)", pair),
GenericNeutral::Split(clauses, argument) => {
f.write_str("app ")?;
argument.fmt(f)?;
f.write_str(" {")?;
write!(f, "app {} {{", argument)?;
fmt_branch(clauses, f)?;
f.write_char('}')
}
Expand All @@ -258,9 +221,7 @@ impl Display for NormalExpression {
match self {
Expression::Lambda(index, expression) => {
f.write_str("\u{03BB} <")?;
index.fmt(f)?;
f.write_str("> ")?;
expression.fmt(f)
write!(f, "{}> {}", index, expression)
}
Expression::Pair(first, second) => write!(f, "({}, {})", first, second),
Expression::Unit => f.write_str("0"),
Expand Down

0 comments on commit fd8d9c0

Please sign in to comment.