diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index 8876c9a..2485047 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -11,7 +11,7 @@ use crate::typechecking::TypeName; type LineNumber = u32; type SymbolTrackTable = HashMap, LineNumber>; -#[derive(PartialEq, Eq, Hash, Debug, Clone)] +#[derive(PartialEq, Eq, Hash, Debug, Clone, PartialOrd, Ord)] pub struct FullyQualifiedSymbolName(pub Vec); impl fmt::Display for FullyQualifiedSymbolName { @@ -24,7 +24,7 @@ impl fmt::Display for FullyQualifiedSymbolName { } } -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct ScopeSegment { pub name: Rc, //TODO maybe this could be a &str, for efficiency? pub kind: ScopeSegmentKind, @@ -49,7 +49,7 @@ impl ScopeSegment { } } -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] pub enum ScopeSegmentKind { Function, Type, @@ -220,7 +220,9 @@ 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 { + let mut sorted_symbols: Vec<(&FullyQualifiedSymbolName, &Symbol)> = self.symbol_path_to_symbol.iter().collect(); + sorted_symbols.sort_by(|(fqsn, _), (other_fqsn, _)| fqsn.cmp(other_fqsn)); + for (name, sym) in sorted_symbols.iter() { write!(output, "{} -> {}\n", name, sym).unwrap(); } output