summaryrefslogtreecommitdiff
path: root/src/syntax/span.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/span.rs')
-rw-r--r--src/syntax/span.rs15
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 {