1#![allow(non_snake_case)]
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct Span {
8 pub head: Loc,
9 pub tail: Loc,
10}
11pub const fn Span(head: Loc, tail: Loc) -> Span {
12 Span { head, tail }
13}
14
15impl Span {
16 pub const fn dummy() -> Self {
17 Span { head: Loc::dummy(), tail: Loc::dummy() }
18 }
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
23pub struct Loc {
24 line: u32,
25 col: u32,
26}
27pub const fn Loc(line: u32, col: u32) -> Loc {
28 Loc { line, col }
29}
30impl Loc {
31 pub const fn dummy() -> Self {
32 Loc { line: 0, col: 0 }
33 }
34 pub const fn line(self) -> u32 {
35 self.line
36 }
37 pub const fn col(self) -> u32 {
38 self.col
39 }
40}
41
42impl std::fmt::Display for Loc {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 let Loc { line, col } = self;
45 write!(f, "{line}:{col}")
46 }
47}