Skip to main content

allium_parser/
span.rs

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