summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/core/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dhall_syntax/src/core/expr.rs')
-rw-r--r--dhall_syntax/src/core/expr.rs18
1 files changed, 14 insertions, 4 deletions
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<E> Expr<E> {
pub fn as_mut(&mut self) -> &mut RawExpr<E> {
&mut self.0.as_mut().0
}
+ pub fn span(&self) -> Option<&Span> {
+ self.0.as_ref().1.as_ref()
+ }
- pub fn new(x: RawExpr<E>, n: Span) -> Self {
+ pub(crate) fn new(x: RawExpr<E>, n: Span) -> Self {
Expr(Box::new((x, Some(n))))
}
@@ -387,9 +400,6 @@ pub fn rc<E>(x: RawExpr<E>) -> Expr<E> {
pub(crate) fn spanned<E>(span: Span, x: RawExpr<E>) -> Expr<E> {
Expr::new(x, span)
}
-pub(crate) fn unspanned<E>(x: RawExpr<E>) -> Expr<E> {
- Expr::from_expr_no_span(x)
-}
/// Add an isize to an usize
/// Panics on over/underflow