xee_interpreter/
span.rs

1use xee_xpath_ast::ast;
2
3/// A span in the source code.
4///
5/// Designates where in the source code a certain error occurred.
6#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize))]
8pub struct SourceSpan(usize, usize);
9
10impl SourceSpan {
11    pub(crate) fn entire(src: &str) -> Self {
12        Self(0, src.len())
13    }
14
15    pub(crate) fn empty() -> Self {
16        Self(0, 0)
17    }
18
19    /// Get the range of the span.
20    pub fn range(&self) -> std::ops::Range<usize> {
21        self.0..self.1
22    }
23}
24
25impl From<ast::Span> for SourceSpan {
26    fn from(span: ast::Span) -> Self {
27        Self(span.start, span.end)
28    }
29}
30
31impl From<std::ops::Range<usize>> for SourceSpan {
32    fn from(range: std::ops::Range<usize>) -> Self {
33        Self(range.start, range.end)
34    }
35}