1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
3pub struct Location {
4 pub line: u64,
6 pub column: u64,
8}
9
10impl Location {
11 pub const fn empty() -> Self {
13 Self { line: 0, column: 0 }
14 }
15
16 pub const fn new(line: u64, column: u64) -> Self {
18 Self { line, column }
19 }
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
24pub struct Span {
25 pub start: Location,
26 pub end: Location,
27}
28
29impl Span {
30 pub const fn empty() -> Self {
32 Self {
33 start: Location::empty(),
34 end: Location::empty(),
35 }
36 }
37
38 pub const fn new(start: Location, end: Location) -> Self {
40 Self { start, end }
41 }
42
43 pub fn union(&self, other: &Span) -> Span {
45 if self.start.line == 0 {
46 return *other;
47 }
48 if other.start.line == 0 {
49 return *self;
50 }
51 Span {
52 start: core::cmp::min(self.start, other.start),
53 end: core::cmp::max(self.end, other.end),
54 }
55 }
56}
57
58pub trait Spanned {
60 fn span(&self) -> Span;
61}