summaryrefslogtreecommitdiff
path: root/src/syntax/span.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-13 11:26:42 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-13 11:26:42 +0100
commita8f711d49ad65ee08c96fae2a8b52873667bdf5c (patch)
tree7f54ec3421e0add1bbb143a1a2244dc9ba958480 /src/syntax/span.rs
parentbd702c2029561a741f48095549a2b6ea97b3a09b (diff)
Checkpoint 🏁
Diffstat (limited to 'src/syntax/span.rs')
-rw-r--r--src/syntax/span.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs
index 9bf7cafb..10188ed4 100644
--- a/src/syntax/span.rs
+++ b/src/syntax/span.rs
@@ -19,7 +19,11 @@ impl<T> Spanned<T> {
self.v
}
- pub fn map<V>(&self, new_v: V) -> Spanned<V> {
+ pub fn map<F, V>(self, f: F) -> Spanned<V> where F: FnOnce(T) -> V {
+ Spanned { v: f(self.v), span: self.span }
+ }
+
+ pub fn map_v<V>(&self, new_v: V) -> Spanned<V> {
Spanned { v: new_v, span: self.span }
}
}
@@ -40,6 +44,8 @@ pub struct Span {
}
impl Span {
+ pub const ZERO: Span = Span { start: Position::ZERO, end: Position::ZERO };
+
pub fn new(start: Position, end: Position) -> Span {
Span { start, end }
}
@@ -78,6 +84,8 @@ pub struct Position {
}
impl Position {
+ pub const ZERO: Position = Position { line: 0, column: 0 };
+
pub fn new(line: usize, column: usize) -> Position {
Position { line, column }
}