Skip to content

Commit 3fec52e

Browse files
minor cleanup
1 parent 8ca1366 commit 3fec52e

2 files changed

Lines changed: 68 additions & 23 deletions

File tree

src/rewrite_system/rise/kind.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl Kindable for Var {
4141
'd' | 't' => Kind::Data,
4242
'a' => Kind::Addr,
4343
'n' => Kind::Nat,
44-
_ => Kind::Expr,
44+
x if x.is_numeric() => Kind::Expr,
45+
x => panic!("Wrong format {x}"),
4546
})
4647
}
4748
}

src/rewrite_system/rise/lang.rs

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,35 +191,79 @@ impl PPNode {
191191
.map(|c_id| Self::new(expr, *c_id, skip_wrapper))
192192
.collect(),
193193
expr: expr[id].to_string().into(),
194-
ty: format!("NO TYPE INFO AVAILABLE {{{}}}", kind_string(&expr[id])).red(),
194+
ty: ("NO TYPE INFO AVAILABLE").red(),
195195
};
196196
};
197197
let node = &expr[*expr_id];
198-
match color_expr(node, skip_wrapper) {
199-
Ok(expr_string) => Self {
200-
children: expr[*expr_id]
201-
.children()
202-
.iter()
203-
.map(|c_id| Self::new(expr, *c_id, skip_wrapper))
204-
.collect(),
205-
expr: expr_string,
206-
ty: format!(
207-
"{} {{{}}}",
208-
pp_ty(expr, *ty_id, false),
209-
kind_string(&expr[*expr_id])
210-
)
211-
.into(),
212-
},
213-
Err(c_id) => Self::new(expr, c_id, skip_wrapper),
198+
let colored_string = match node {
199+
Rise::Var(index) => index.to_string().magenta(),
200+
Rise::App(_) | Rise::Lambda(_) => node.to_string().red(),
201+
Rise::NatApp(_) | Rise::DataApp(_) | Rise::AddrApp(_) | Rise::NatNatApp(_) => {
202+
node.to_string().cyan()
203+
}
204+
Rise::NatLambda(c_id)
205+
| Rise::DataLambda(c_id)
206+
| Rise::AddrLambda(c_id)
207+
| Rise::NatNatLambda(c_id) => {
208+
if skip_wrapper {
209+
return Self::new(expr, *c_id, skip_wrapper);
210+
}
211+
node.to_string().cyan()
212+
}
213+
Rise::FunType(_)
214+
| Rise::NatFun(_)
215+
| Rise::DataFun(_)
216+
| Rise::AddrFun(_)
217+
| Rise::NatNatFun(_)
218+
| Rise::TypeOf(_)
219+
| Rise::ArrType(_)
220+
| Rise::VecType(_)
221+
| Rise::PairType(_)
222+
| Rise::IndexType(_)
223+
| Rise::NatType
224+
| Rise::F32 => panic!("Should not see types here: {node}"),
225+
Rise::NatAdd(_)
226+
| Rise::NatSub(_)
227+
| Rise::NatMul(_)
228+
| Rise::NatDiv(_)
229+
| Rise::NatPow(_) => {
230+
panic!("NatExpr should only appear in types: {node}")
231+
} // node.to_string().white()
232+
Rise::Let
233+
| Rise::AsVector
234+
| Rise::AsScalar
235+
| Rise::VectorFromScalar
236+
| Rise::Snd
237+
| Rise::Fst
238+
| Rise::Add
239+
| Rise::Mul
240+
| Rise::ToMem
241+
| Rise::Split
242+
| Rise::Join
243+
| Rise::Generate
244+
| Rise::Transpose
245+
| Rise::Zip
246+
| Rise::Unzip
247+
| Rise::Map
248+
| Rise::MapPar
249+
| Rise::Reduce
250+
| Rise::ReduceSeq
251+
| Rise::ReduceSeqUnroll
252+
| Rise::Float(_) => node.to_string().yellow(),
253+
Rise::Integer(i) => format!("int{i}").purple(),
254+
};
255+
Self {
256+
children: expr[*expr_id]
257+
.children()
258+
.iter()
259+
.map(|c_id| Self::new(expr, *c_id, skip_wrapper))
260+
.collect(),
261+
expr: colored_string,
262+
ty: pp_ty(expr, *ty_id, false),
214263
}
215264
}
216265
}
217266

218-
fn kind_string(node: &Rise) -> String {
219-
node.kind()
220-
.map_or_else(|| String::from("UNKINDABLE"), |k| k.to_string())
221-
}
222-
223267
fn color_expr(node: &Rise, skip_wrapper: bool) -> Result<ColoredString, Id> {
224268
let colored_string = match node {
225269
Rise::Var(index) => index.to_string().magenta(),

0 commit comments

Comments
 (0)