From 2f6f21c52e60c560eb4c5fff9441b7d20c8c1d9a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 3 Sep 2019 23:01:55 +0200 Subject: Store Spans at every node when parsing --- dhall_syntax/src/core/expr.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'dhall_syntax/src/core/expr.rs') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 2cb23c9..455e42a 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -37,6 +37,16 @@ impl Span { end: sp.end(), } } + /// Takes the union of the two spans. Assumes that the spans come from the same input. + /// This will also capture any input between the spans. + pub fn union(&self, other: &Span) -> Self { + use std::cmp::{max, min}; + Span { + input: self.input.clone(), + start: min(self.start, other.start), + end: max(self.start, other.start), + } + } } /// Double with bitwise equality @@ -324,8 +334,11 @@ impl Expr { pub fn as_mut(&mut self) -> &mut RawExpr { &mut self.0.as_mut().0 } + pub fn span(&self) -> Option<&Span> { + self.0.as_ref().1.as_ref() + } - pub fn new(x: RawExpr, n: Span) -> Self { + pub(crate) fn new(x: RawExpr, n: Span) -> Self { Expr(Box::new((x, Some(n)))) } @@ -387,9 +400,6 @@ pub fn rc(x: RawExpr) -> Expr { pub(crate) fn spanned(span: Span, x: RawExpr) -> Expr { Expr::new(x, span) } -pub(crate) fn unspanned(x: RawExpr) -> Expr { - Expr::from_expr_no_span(x) -} /// Add an isize to an usize /// Panics on over/underflow -- cgit v1.2.3 From 0388d9858627693bab2433f134eb4ed1d6e9b164 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 6 Sep 2019 18:17:36 +0200 Subject: Make ParseInput independent from dhall-specific types --- dhall_syntax/src/core/expr.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'dhall_syntax/src/core/expr.rs') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 455e42a..74b481f 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -334,8 +334,8 @@ impl Expr { pub fn as_mut(&mut self) -> &mut RawExpr { &mut self.0.as_mut().0 } - pub fn span(&self) -> Option<&Span> { - self.0.as_ref().1.as_ref() + pub fn span(&self) -> Option { + self.0.as_ref().1.clone() } pub(crate) fn new(x: RawExpr, n: Span) -> Self { @@ -397,10 +397,6 @@ pub fn rc(x: RawExpr) -> Expr { Expr::from_expr_no_span(x) } -pub(crate) fn spanned(span: Span, x: RawExpr) -> Expr { - Expr::new(x, span) -} - /// Add an isize to an usize /// Panics on over/underflow fn add_ui(u: usize, i: isize) -> Option { -- cgit v1.2.3