From a8f711d49ad65ee08c96fae2a8b52873667bdf5c Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 13 Jan 2020 11:26:42 +0100 Subject: =?UTF-8?q?Checkpoint=20=F0=9F=8F=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/span.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/syntax/span.rs') 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 Spanned { self.v } - pub fn map(&self, new_v: V) -> Spanned { + pub fn map(self, f: F) -> Spanned where F: FnOnce(T) -> V { + Spanned { v: f(self.v), span: self.span } + } + + pub fn map_v(&self, new_v: V) -> Spanned { 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 } } -- cgit v1.2.3