diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index f282ce5..2095792 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -14,12 +14,34 @@ type SymbolTrackTable = HashMap, LineNumber>; #[derive(PartialEq, Eq, Hash, Debug, Clone)] pub struct FullyQualifiedSymbolName(pub Vec); +impl fmt::Display for FullyQualifiedSymbolName { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let FullyQualifiedSymbolName(v) = self; + for segment in v { + write!(f, "::{}", segment)?; + } + Ok(()) + } +} + #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub struct ScopeSegment { name: Rc, //TODO maybe this could be a &str, for efficiency? kind: ScopeSegmentKind, } +impl fmt::Display for ScopeSegment { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use ScopeSegmentKind::*; + let kind = match self.kind { + Function => "fn", + Type => "ty", + Terminal => "tr", + }; + write!(f, "{}({})", self.name, kind) + } +} + impl ScopeSegment { pub fn new(name: Rc, kind: ScopeSegmentKind) -> ScopeSegment { ScopeSegment { name, kind } @@ -199,7 +221,7 @@ impl SymbolTable { pub fn debug_symbol_table(&self) -> String { let mut output = format!("Symbol table\n"); for (name, sym) in &self.symbol_path_to_symbol { - write!(output, "{:?} -> {}\n", name, sym).unwrap(); + write!(output, "{} -> {}\n", name, sym).unwrap(); } output }