pub use verter_span::{GeneratedSpan, PartialGeneratedSpan, RelativeSpan, Span};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize)]
pub struct Position {
pub column: u32,
pub line: u32,
#[serde(skip)]
pub offset: u32,
#[serde(rename = "offset")]
pub offset_utf16: u32,
}
impl Position {
#[inline]
pub const fn new(offset: u32, line: u32, column: u32, offset_utf16: u32) -> Self {
Self {
offset,
line,
column,
offset_utf16,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize)]
pub struct SourceLocation<'a> {
pub start: Position,
pub end: Position,
pub source: &'a str,
}
impl<'a> SourceLocation<'a> {
#[inline]
pub const fn new(start: Position, end: Position) -> Self {
Self {
start,
end,
source: "",
}
}
#[inline]
pub fn from_source(source: &'a str, start: Position, end: Position) -> Self {
Self {
start,
end,
source: &source[start.offset as usize..end.offset as usize],
}
}
#[inline]
pub const fn new_with_source(start: Position, end: Position, source: &'a str) -> Self {
Self { start, end, source }
}
#[inline]
pub const fn empty_at(pos: Position) -> Self {
Self {
start: pos,
end: pos,
source: "",
}
}
}