Skip to main content

allium_parser/
span.rs

1/// Byte offset range in source text. Attached to every AST node
2/// so diagnostics can point at the exact source location.
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub struct Span {
5    pub start: usize,
6    pub end: usize,
7}
8
9impl Span {
10    pub fn new(start: usize, end: usize) -> Self {
11        Self { start, end }
12    }
13
14    pub fn merge(self, other: Span) -> Span {
15        Span {
16            start: self.start.min(other.start),
17            end: self.end.max(other.end),
18        }
19    }
20}