Skip to main content

ron_schema/
span.rs

1/*************************
2 * Author: Bradley Hunter
3 */
4
5
6/// A single point in source text, tracking both byte offset and human-readable coordinates.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8pub struct Position {
9    /// Byte offset from the start of the source string (0-based).
10    pub offset: usize,
11    /// Line number (1-based).
12    pub line: usize,
13    /// Column number (1-based, byte-based).
14    pub column: usize,
15}
16
17/// A range in source text, defined by a start and end [`Position`].
18///
19/// Uses Rust's standard range convention: start is inclusive, end is exclusive.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct Span {
22    /// Start of the spanned region (inclusive).
23    pub start: Position,
24    /// End of the spanned region (exclusive).
25    pub end: Position,
26}
27
28/// A value paired with the [`Span`] indicating where it appeared in the source text.
29#[derive(Debug, Clone, PartialEq)]
30pub struct Spanned<T> {
31    /// The wrapped value.
32    pub value: T,
33    /// Source location of this value.
34    pub span: Span,
35}