use crate::position::Position;
#[derive(Debug, PartialEq, Clone, Copy, Default)]
pub struct Range {
pub start: Position,
pub end_inclusive: Position,
}
impl Range {
pub fn new(start: &Position, end_inclusive: &Position) -> Self {
Self {
start: *start,
end_inclusive: *end_inclusive,
}
}
pub fn from_single_position(pos: &Position) -> Self {
Self {
start: *pos,
end_inclusive: *pos,
}
}
pub fn from_position_and_length(pos: &Position, length: usize) -> Self {
let inc = length - 1;
Self {
start: *pos,
end_inclusive: Position::new(pos.index + inc, pos.line, pos.column + inc),
}
}
pub fn from_detail(index: usize, line: usize, column: usize, length: usize) -> Self {
let inc = length - 1;
let start = Position::new(index, line, column);
let end_inclusive = Position::new(index + inc, line, column + inc);
Self {
start,
end_inclusive,
}
}
pub fn merge(left: &Self, right: &Self) -> Self {
Self {
start: left.start,
end_inclusive: right.end_inclusive,
}
}
}