online_dsl_forge/parser/
span.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
4pub struct SourceSpan {
5 pub start: usize,
6 pub end: usize,
7}
8
9impl SourceSpan {
10 pub fn new(start: usize, end: usize) -> Self {
11 Self { start, end }
12 }
13
14 pub fn join(self, other: Self) -> Self {
15 Self {
16 start: self.start.min(other.start),
17 end: self.end.max(other.end),
18 }
19 }
20
21 pub fn is_empty(self) -> bool {
22 self.start == self.end
23 }
24}