use microcad_lang_base::{
ComputedHash, GetSourceLocInfoByHash, Hashed, Refer, SourceLocInfo, SrcRef, SrcReferrer, Url,
};
use crate::ast;
pub struct Source {
pub url: Url,
pub line_offset: u32,
pub code: Hashed<String>,
pub ast: Refer<ast::Program>,
}
impl SrcReferrer for Source {
fn src_ref(&self) -> SrcRef {
self.ast.src_ref()
}
}
impl GetSourceLocInfoByHash for Source {
fn get_source_loc_info_by_hash(
&'_ self,
hash: microcad_lang_base::HashId,
) -> Option<microcad_lang_base::SourceLocInfo<'_>> {
if hash == self.code.computed_hash() {
Some(SourceLocInfo {
code: &self.code,
url: self.url.clone(),
line_offset: self.line_offset,
})
} else {
None
}
}
}