From 53ca5a7fc5829d4c5b1cffc6d5a5f1706f8ec3cd Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 27 Jul 2020 13:47:29 +0200 Subject: =?UTF-8?q?Refactor=20parser=20=F0=9F=9A=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/span.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/syntax/span.rs') diff --git a/src/syntax/span.rs b/src/syntax/span.rs index 8083bc06..c8e2cddb 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -4,14 +4,14 @@ use std::fmt::{self, Debug, Formatter}; use std::ops::{Add, Sub}; use serde::Serialize; -/// A vector of spanned things. +/// A vector of spanned values of type `T`. pub type SpanVec = Vec>; /// [Offset](Span::offset) all spans in a vector of spanned things by a start /// position. pub fn offset_spans( - start: Position, vec: SpanVec, + start: Position, ) -> impl Iterator> { vec.into_iter().map(move |s| s.map_span(|span| span.offset(start))) } @@ -95,6 +95,11 @@ impl Span { Span { start: pos, end: pos } } + /// Expand a span by merging it with another span. + pub fn expand(&mut self, other: Span) { + *self = Span::merge(*self, other) + } + /// Offset a span by a start position. /// /// This is, for example, used to translate error spans from function local @@ -126,7 +131,7 @@ impl Position { /// The line 0, column 0 position. pub const ZERO: Position = Position { line: 0, column: 0 }; - /// Crete a new instance from line and column. + /// Create a new position from line and column. pub fn new(line: usize, column: usize) -> Position { Position { line, column } } -- cgit v1.2.3