From 5fcc7f69c7a68b08ff223217e8af9f8edb2cc761 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 12 Apr 2019 16:32:29 +0200 Subject: Capture `Span`s in the AST and thread them through Parsed and Resolved --- dhall/src/expr.rs | 8 ++------ dhall/src/imports.rs | 11 +++++------ dhall/src/typecheck.rs | 6 +++--- 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'dhall') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 3987896..ab59ce0 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -23,17 +23,13 @@ macro_rules! derive_other_traits { #[derive(Debug, Clone, Eq)] pub struct Parsed<'a>( - pub(crate) SubExpr, + pub(crate) SubExpr, Import>, pub(crate) ImportRoot, - pub(crate) PhantomData<&'a ()>, ); derive_other_traits!(Parsed); #[derive(Debug, Clone, Eq)] -pub struct Resolved<'a>( - pub(crate) SubExpr>, - pub(crate) PhantomData<&'a ()>, -); +pub struct Resolved<'a>(pub(crate) SubExpr, Normalized<'static>>); derive_other_traits!(Resolved); #[derive(Debug, Clone, Eq)] diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index cc9654a..36f0802 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -3,7 +3,6 @@ use crate::expr::*; use dhall_core::*; use std::fs::File; use std::io::Read; -use std::marker::PhantomData; use std::path::Path; use std::path::PathBuf; @@ -50,7 +49,7 @@ fn load_import(f: &Path) -> Result, Error> { } fn resolve_expr<'a>( - Parsed(expr, root, marker): Parsed<'a>, + Parsed(expr, root): Parsed<'a>, allow_imports: bool, ) -> Result, ImportError> { let resolve = @@ -63,7 +62,7 @@ fn resolve_expr<'a>( } }; let expr = expr.as_ref().traverse_embed(&resolve)?; - Ok(Resolved(rc(expr), marker)) + Ok(Resolved(rc(expr))) } impl<'a> Parsed<'a> { @@ -72,13 +71,13 @@ impl<'a> Parsed<'a> { File::open(f)?.read_to_string(&mut buffer)?; let expr = parse_expr(&*buffer)?; let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); - Ok(Parsed(expr, root, PhantomData)) + Ok(Parsed(expr.unnote().note_absurd(), root)) } pub fn parse_str(s: &'a str) -> Result, Error> { let expr = parse_expr(s)?; let root = ImportRoot::LocalDir(std::env::current_dir()?); - Ok(Parsed(expr, root, PhantomData)) + Ok(Parsed(expr, root)) } pub fn parse_binary_file(f: &Path) -> Result, Error> { @@ -86,7 +85,7 @@ impl<'a> Parsed<'a> { File::open(f)?.read_to_end(&mut buffer)?; let expr = crate::binary::decode(&buffer)?; let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); - Ok(Parsed(expr, root, PhantomData)) + Ok(Parsed(expr.note_absurd(), root)) } pub fn resolve(self) -> Result, ImportError> { diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index d98095c..5a28089 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -14,19 +14,19 @@ use self::TypeMessage::*; impl<'a> Resolved<'a> { pub fn typecheck(self) -> Result, TypeError> { - type_of(self.0.clone()) + type_of(self.0.unnote()) } pub fn typecheck_with( self, ty: &Type, ) -> Result, TypeError> { - let expr: SubExpr<_, _> = self.0.clone(); + let expr: SubExpr<_, _> = self.0.unnote(); let ty: SubExpr<_, _> = ty.as_normalized()?.as_expr().absurd(); type_of(dhall::subexpr!(expr: ty)) } /// Pretends this expression has been typechecked. Use with care. pub fn skip_typecheck(self) -> Typed<'a> { - Typed(self.0, None, self.1) + Typed(self.0.unnote(), None, PhantomData) } } impl<'a> Typed<'a> { -- cgit v1.2.3