FullyQualifiedSymbolName string representation
This commit is contained in:
parent
0540df4024
commit
89d967aee4
@ -14,12 +14,34 @@ type SymbolTrackTable = HashMap<Rc<String>, LineNumber>;
|
||||
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
||||
pub struct FullyQualifiedSymbolName(pub Vec<ScopeSegment>);
|
||||
|
||||
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<String>, //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<String>, 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user