1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct Span {
8 pub start: Position,
9 pub end: Position,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct Position {
15 pub line: usize,
16 pub column: usize,
17}
18
19impl Span {
20 pub fn new(start: Position, end: Position) -> Self {
21 Self { start, end }
22 }
23
24 pub fn from_coords(
26 start_line: usize,
27 start_col: usize,
28 end_line: usize,
29 end_col: usize,
30 ) -> Self {
31 Self {
32 start: Position::new(start_line, start_col),
33 end: Position::new(end_line, end_col),
34 }
35 }
36
37 pub fn contains(&self, position: Position) -> bool {
39 if position.line < self.start.line || position.line > self.end.line {
40 return false;
41 }
42 if position.line == self.start.line && position.column < self.start.column {
43 return false;
44 }
45 if position.line == self.end.line && position.column > self.end.column {
46 return false;
47 }
48 true
49 }
50}
51
52impl Position {
53 pub fn new(line: usize, column: usize) -> Self {
54 Self { line, column }
55 }
56}