microcad_lang_parse/ast/
source.rs1use microcad_lang_base::{
7 ComputedHash, GetSourceLocInfoByHash, Hashed, Refer, SourceLocInfo, SrcRef, SrcReferrer, Url,
8};
9
10use crate::ast;
11
12pub struct Source {
14 pub url: Url,
16 pub line_offset: u32,
18 pub code: Hashed<String>,
20 pub ast: Refer<ast::Program>,
22}
23
24impl SrcReferrer for Source {
25 fn src_ref(&self) -> SrcRef {
26 self.ast.src_ref()
27 }
28}
29
30impl GetSourceLocInfoByHash for Source {
31 fn get_source_loc_info_by_hash(
32 &'_ self,
33 hash: microcad_lang_base::HashId,
34 ) -> Option<microcad_lang_base::SourceLocInfo<'_>> {
35 if hash == self.code.computed_hash() {
36 Some(SourceLocInfo {
37 code: &self.code,
38 url: self.url.clone(),
39 line_offset: self.line_offset,
40 })
41 } else {
42 None
43 }
44 }
45}