From fb0bf2982618caf3053901d6316e40e08f96ae60 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 25 Oct 2021 12:47:35 -0700 Subject: [PATCH] Add Display impl for FQSN --- schala-lang/language/src/symbol_table/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 7da29cb..8f54f54 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -83,6 +83,19 @@ impl Fqsn { } } +impl fmt::Display for Fqsn { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let delim = "::"; + let Fqsn { scopes } = self; + write!(f, "FQSN<{}", scopes[0])?; + for item in scopes[1..].iter() { + write!(f, "{}{}", delim, item)?; + } + write!(f, ">") + } +} + + //TODO eventually this should use ItemId's to avoid String-cloning /// One segment within a scope. #[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] @@ -90,6 +103,13 @@ enum Scope { Name(Rc), } +impl fmt::Display for Scope { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Scope::Name(name) = self; + write!(f, "{}", name) + } +} + #[allow(dead_code)] #[derive(Debug, Clone)] pub enum SymbolError {