cl-structures: Make Span and Loc functions const (now you can make a const Span!)

This commit is contained in:
John 2024-04-22 21:44:12 -05:00
parent b74c4cd5bf
commit 45d75bb552

View File

@ -8,24 +8,33 @@ pub struct Span {
pub head: Loc,
pub tail: Loc,
}
pub fn Span(head: Loc, tail: Loc) -> Span {
pub const fn Span(head: Loc, tail: Loc) -> Span {
Span { head, tail }
}
impl Span {
pub const fn dummy() -> Self {
Span { head: Loc::dummy(), tail: Loc::dummy() }
}
}
/// Stores a read-only (line, column) location in a token stream
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Loc {
line: u32,
col: u32,
}
pub fn Loc(line: u32, col: u32) -> Loc {
pub const fn Loc(line: u32, col: u32) -> Loc {
Loc { line, col }
}
impl Loc {
pub fn line(self) -> u32 {
pub const fn dummy() -> Self {
Loc { line: 0, col: 0 }
}
pub const fn line(self) -> u32 {
self.line
}
pub fn col(self) -> u32 {
pub const fn col(self) -> u32 {
self.col
}
}