assembler/
span.rs

1//! Representation of locations within the original source file.
2use chumsky::prelude::SimpleSpan;
3use std::ops::Range;
4
5pub(crate) type Span = SimpleSpan;
6
7pub(crate) trait Spanned {
8    fn span(&self) -> Span;
9}
10
11pub(crate) fn span(range: Range<usize>) -> Span {
12    Span::from(range)
13}
14
15#[derive(Debug, Clone)]
16pub(crate) struct OrderableSpan(pub(crate) Span);
17
18impl From<Span> for OrderableSpan {
19    fn from(span: Span) -> OrderableSpan {
20        OrderableSpan(span)
21    }
22}
23
24impl Ord for OrderableSpan {
25    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
26        self.0.start.cmp(&other.0.start)
27    }
28}
29
30impl PartialOrd for OrderableSpan {
31    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
32        Some(self.cmp(other))
33    }
34}
35
36impl PartialEq for OrderableSpan {
37    fn eq(&self, other: &Self) -> bool {
38        self.0.start.cmp(&other.0.start).is_eq()
39    }
40}
41
42impl Eq for OrderableSpan {}
43
44impl OrderableSpan {
45    pub(super) fn as_span(&self) -> &Span {
46        &self.0
47    }
48}