Skip to main content

weavatrix_graph/model/
span.rs

1use crate::String;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
5pub struct SourcePosition {
6    /// One-based line number.
7    pub line: u32,
8    /// One-based byte column.
9    pub column: u32,
10}
11
12impl SourcePosition {
13    #[must_use]
14    pub const fn new(line: u32, column: u32) -> Self {
15        Self { line, column }
16    }
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
20pub struct SourceSpan {
21    pub file: String,
22    pub start: SourcePosition,
23    /// Exclusive end position.
24    pub end: SourcePosition,
25}
26
27impl SourceSpan {
28    #[must_use]
29    pub fn new(file: impl Into<String>, start: SourcePosition, end: SourcePosition) -> Self {
30        Self {
31            file: file.into(),
32            start,
33            end,
34        }
35    }
36}