From 889610f0b0b0dc69c438a7fa815af18cd9f850ba Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Jun 2018 23:04:07 -0700 Subject: [PATCH] Pretty-print Symbol Table --- schala-lang/src/builtin.rs | 1 - schala-lang/src/symbol_table.rs | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/builtin.rs b/schala-lang/src/builtin.rs index 8fe0504..b30a0c2 100644 --- a/schala-lang/src/builtin.rs +++ b/schala-lang/src/builtin.rs @@ -19,7 +19,6 @@ pub enum TConstOld { Float, StringT, Bool, - Custom(String), } impl fmt::Display for Type { diff --git a/schala-lang/src/symbol_table.rs b/schala-lang/src/symbol_table.rs index 9d65b77..e584ce9 100644 --- a/schala-lang/src/symbol_table.rs +++ b/schala-lang/src/symbol_table.rs @@ -23,6 +23,12 @@ pub struct Symbol { pub spec: SymbolSpec, } +impl fmt::Display for Symbol { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "", self.name, self.spec) + } +} + #[derive(Debug)] pub enum SymbolSpec { Func(Vec), @@ -32,6 +38,16 @@ pub enum SymbolSpec { }, } +impl fmt::Display for SymbolSpec { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::SymbolSpec::*; + match self { + Func(type_names) => write!(f, "Func({:?})", type_names), + DataConstructor { type_name, type_args } => write!(f, "DataConstructor({:?} -> {})", type_args, type_name), + } + } +} + impl SymbolTable { /* note: this adds names for *forward reference* but doesn't actually create any types. solve that problem * later */ @@ -97,8 +113,8 @@ impl SymbolTable { } pub fn debug_symbol_table(&self) -> String { let mut output = format!("Symbol table\n"); - for (sym, ty) in &self.values { - write!(output, "{} -> {:?}\n", sym, ty).unwrap(); + for (name, sym) in &self.values { + write!(output, "{} -> {}\n", name, sym).unwrap(); } output }