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)]
|
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
||||||
pub struct FullyQualifiedSymbolName(pub Vec<ScopeSegment>);
|
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)]
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct ScopeSegment {
|
pub struct ScopeSegment {
|
||||||
name: Rc<String>, //TODO maybe this could be a &str, for efficiency?
|
name: Rc<String>, //TODO maybe this could be a &str, for efficiency?
|
||||||
kind: ScopeSegmentKind,
|
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 {
|
impl ScopeSegment {
|
||||||
pub fn new(name: Rc<String>, kind: ScopeSegmentKind) -> ScopeSegment {
|
pub fn new(name: Rc<String>, kind: ScopeSegmentKind) -> ScopeSegment {
|
||||||
ScopeSegment { name, kind }
|
ScopeSegment { name, kind }
|
||||||
@ -199,7 +221,7 @@ impl SymbolTable {
|
|||||||
pub fn debug_symbol_table(&self) -> String {
|
pub fn debug_symbol_table(&self) -> String {
|
||||||
let mut output = format!("Symbol table\n");
|
let mut output = format!("Symbol table\n");
|
||||||
for (name, sym) in &self.symbol_path_to_symbol {
|
for (name, sym) in &self.symbol_path_to_symbol {
|
||||||
write!(output, "{:?} -> {}\n", name, sym).unwrap();
|
write!(output, "{} -> {}\n", name, sym).unwrap();
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user