diff options
| author | Martin Haug <mhaug@live.de> | 2021-10-23 19:03:27 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2021-11-05 13:44:49 +0100 |
| commit | 4875633acf4701705b9b3b014eb7d94268b897c2 (patch) | |
| tree | 0aedda87c8c2dc65316e2455c35e72054d9bae0e /src/syntax/span.rs | |
| parent | ea6ee3f667e922ed2f21b08719a45d2395787932 (diff) | |
Change parser
Diffstat (limited to 'src/syntax/span.rs')
| -rw-r--r-- | src/syntax/span.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs index bfb9e755..ee7cba4c 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -109,6 +109,11 @@ impl Span { *self = self.join(other) } + /// Test whether a position is within the span. + pub fn contains_pos(&self, pos: Pos) -> bool { + self.start <= pos && self.end >= pos + } + /// Test whether one span complete contains the other span. pub fn contains(self, other: Self) -> bool { self.source == other.source && self.start <= other.start && self.end >= other.end @@ -118,6 +123,16 @@ impl Span { pub fn to_range(self) -> Range<usize> { self.start.to_usize() .. self.end.to_usize() } + + /// A new span at the position of this span's start. + pub fn at_start(&self) -> Span { + Self::at(self.source, self.start) + } + + /// A new span at the position of this span's end. + pub fn at_end(&self) -> Span { + Self::at(self.source, self.end) + } } impl Debug for Span { |
