leap_lang/parser/
position.rs1use std::cmp::max;
2
3#[derive(PartialEq, Clone, Copy, Debug)]
5pub struct Position {
6 pub start: usize, pub length: usize, }
9
10impl Position {
11 pub fn new(start: usize, length: usize) -> Self {
12 Position { start, length }
13 }
14
15 pub fn end(&self) -> usize {
16 self.start + self.length
17 }
18
19 pub fn extend(&self, pos: &Self) -> Self {
20 let length = max(self.length, pos.start + pos.length - self.start);
21 Self {
22 start: self.start,
23 length,
24 }
25 }
26}