implement unparse()
This commit is contained in:
parent
167da369af
commit
29d1acd681
2 changed files with 48 additions and 0 deletions
|
@ -4,6 +4,7 @@ pub mod dict;
|
|||
pub mod term;
|
||||
pub mod lexer;
|
||||
pub mod parser;
|
||||
pub mod unparser;
|
||||
pub mod curry;
|
||||
pub mod lnf;
|
||||
pub mod subtype;
|
||||
|
|
47
src/unparser.rs
Normal file
47
src/unparser.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use crate::{dict::*, term::*};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||
|
||||
impl TypeDict {
|
||||
pub fn unparse(&self, t: &TypeTerm) -> String {
|
||||
match t {
|
||||
TypeTerm::TypeID(id) => self.get_typename(id).unwrap(),
|
||||
TypeTerm::Num(n) => format!("{}", n),
|
||||
TypeTerm::Char(c) => match c {
|
||||
'\0' => "'\\0'".into(),
|
||||
'\n' => "'\\n'".into(),
|
||||
'\t' => "'\\t'".into(),
|
||||
'\'' => "'\\''".into(),
|
||||
c => format!("'{}'", c)
|
||||
},
|
||||
TypeTerm::Ladder(rungs) => {
|
||||
let mut s = String::new();
|
||||
let mut first = true;
|
||||
for r in rungs.iter() {
|
||||
if !first {
|
||||
s.push('~');
|
||||
}
|
||||
first = false;
|
||||
s.push_str(&mut self.unparse(r));
|
||||
}
|
||||
s
|
||||
}
|
||||
TypeTerm::App(args) => {
|
||||
let mut s = String::new();
|
||||
s.push('<');
|
||||
let mut first = true;
|
||||
for r in args.iter() {
|
||||
if !first {
|
||||
s.push(' ');
|
||||
}
|
||||
first = false;
|
||||
s.push_str(&mut self.unparse(r));
|
||||
}
|
||||
s.push('>');
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
Loading…
Reference in a new issue