diff options
author | Nadrieril Feneanar | 2019-11-11 17:01:02 +0100 |
---|---|---|
committer | GitHub | 2019-11-11 17:01:02 +0100 |
commit | 84cd6f386d6f4c7952fbc1da87dcd754f26ee404 (patch) | |
tree | d348f580a00c4b97f04f3a2e41ea2a23d67af824 /dhall_syntax/src/core/expr.rs | |
parent | f58ff637c8d53af1fcee43bfba5a9f8de799084c (diff) | |
parent | 8b566b2575096562c2e15d6ac9ee8750db2cf14f (diff) |
Merge pull request #114 from Nadrieril/nice-type-errors
Ground work for pretty type errors
Diffstat (limited to 'dhall_syntax/src/core/expr.rs')
-rw-r--r-- | dhall_syntax/src/core/expr.rs | 53 |
1 files changed, 4 insertions, 49 deletions
diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 2ad3ba8..750b58b 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; - use crate::map::{DupTreeMap, DupTreeSet}; use crate::visitor::{self, ExprFMutVisitor, ExprFVisitor}; use crate::*; @@ -15,40 +13,6 @@ pub fn trivial_result<T>(x: Result<T, !>) -> T { } } -/// A location in the source text -#[derive(Debug, Clone)] -pub struct Span { - input: Rc<str>, - /// # Safety - /// - /// Must be a valid character boundary index into `input`. - start: usize, - /// # Safety - /// - /// Must be a valid character boundary index into `input`. - end: usize, -} - -impl Span { - pub(crate) fn make(input: Rc<str>, sp: pest::Span) -> Self { - Span { - input, - start: sp.start(), - 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 #[derive(Debug, Copy, Clone)] pub struct NaiveDouble(f64); @@ -178,7 +142,7 @@ pub enum Builtin { // Each node carries an annotation. #[derive(Debug, Clone)] -pub struct Expr<Embed>(Box<(RawExpr<Embed>, Option<Span>)>); +pub struct Expr<Embed>(Box<(RawExpr<Embed>, Span)>); pub type RawExpr<Embed> = ExprF<Expr<Embed>, Embed>; @@ -334,16 +298,12 @@ 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> { + pub fn span(&self) -> Span { self.0.as_ref().1.clone() } - pub(crate) fn new(x: RawExpr<E>, n: Span) -> Self { - Expr(Box::new((x, Some(n)))) - } - - pub fn from_expr_no_span(x: RawExpr<E>) -> Self { - Expr(Box::new((x, None))) + pub fn new(x: RawExpr<E>, n: Span) -> Self { + Expr(Box::new((x, n))) } pub fn rewrap<E2>(&self, x: RawExpr<E2>) -> Expr<E2> { @@ -388,11 +348,6 @@ impl<E> Expr<E> { } } -// Should probably rename this -pub fn rc<E>(x: RawExpr<E>) -> Expr<E> { - Expr::from_expr_no_span(x) -} - /// Add an isize to an usize /// Panics on over/underflow fn add_ui(u: usize, i: isize) -> Option<usize> { |