mimium_lang/utils/
metadata.rs

1use std::path::PathBuf;
2
3use crate::interner::{Symbol, ToSymbol};
4
5pub type Span = std::ops::Range<usize>;
6
7#[derive(Clone, Debug, PartialEq)]
8pub struct Location {
9    pub span: Span,
10    pub path: PathBuf,
11}
12impl Location {
13    pub fn new(span: Span, path: PathBuf) -> Self {
14        Self { span, path }
15    }
16}
17impl Default for Location {
18    fn default() -> Self {
19        Self {
20            span: 0..0,
21            path: PathBuf::new(),
22        }
23    }
24}
25
26impl ariadne::Span for Location {
27    type SourceId = PathBuf;
28
29    fn source(&self) -> &Self::SourceId {
30        &self.path
31    }
32
33    fn start(&self) -> usize {
34        self.span.start
35    }
36
37    fn end(&self) -> usize {
38        self.span.end
39    }
40}
41
42// #[derive(Clone, Debug, PartialEq)]
43// pub struct WithMeta<T>{
44//     pub location: Span,
45//     pub value : T
46// }
47pub(crate) const GLOBAL_LABEL: &str = "_mimium_global";
48
49// #[derive(Clone, Debug, PartialEq)]
50// pub struct WithMeta<T: Clone + PartialEq>(pub T, pub Span);
51
52// impl<T: Clone + PartialEq> WithMeta<T> {
53//     fn map<F, O>(self, f: F) -> WithMeta<O>
54//     where
55//         F: FnOnce(T) -> O,
56//         O: Clone + PartialEq,
57//     {
58//         WithMeta(f(self.0), self.1)
59//     }
60// }