summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/expr.rs58
-rw-r--r--dhall/src/syntax/ast/visitor.rs30
2 files changed, 31 insertions, 57 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 420df5b..722630f 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -96,19 +96,19 @@ pub enum Builtin {
// Each node carries an annotation.
#[derive(Debug, Clone)]
-pub struct Expr<Embed> {
- kind: Box<ExprKind<Expr<Embed>, Embed>>,
+pub struct Expr {
+ kind: Box<ExprKind<Expr>>,
span: Span,
}
-pub type UnspannedExpr<Embed> = ExprKind<Expr<Embed>, Embed>;
+pub type UnspannedExpr = ExprKind<Expr>;
/// Syntax tree for expressions
// Having the recursion out of the enum definition enables writing
// much more generic code and improves pattern-matching behind
// smart pointers.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum ExprKind<SubExpr, Embed> {
+pub enum ExprKind<SubExpr> {
Const(Const),
/// `x`
/// `x@n`
@@ -169,18 +169,13 @@ pub enum ExprKind<SubExpr, Embed> {
Completion(SubExpr, SubExpr),
/// `./some/path`
Import(Import<SubExpr>),
- /// Embeds the result of resolving an import
- Embed(Embed),
}
-impl<SE, E> ExprKind<SE, E> {
+impl<SE> ExprKind<SE> {
pub fn traverse_ref_maybe_binder<'a, SE2, Err>(
&'a self,
visit: impl FnMut(Option<&'a Label>, &'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
visitor::TraverseRefMaybeBinderVisitor(visit).visit(self)
}
@@ -188,10 +183,7 @@ impl<SE, E> ExprKind<SE, E> {
&'a self,
mut visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
mut visit_under_binder: impl FnMut(&'a Label, &'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
self.traverse_ref_maybe_binder(|l, x| match l {
None => visit_subexpr(x),
Some(l) => visit_under_binder(l, x),
@@ -201,20 +193,14 @@ impl<SE, E> ExprKind<SE, E> {
pub(crate) fn traverse_ref<'a, SE2, Err>(
&'a self,
mut visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
self.traverse_ref_maybe_binder(|_, e| visit_subexpr(e))
}
pub fn map_ref_maybe_binder<'a, SE2>(
&'a self,
mut map: impl FnMut(Option<&'a Label>, &'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
trivial_result(self.traverse_ref_maybe_binder(|l, x| Ok(map(l, x))))
}
@@ -222,10 +208,7 @@ impl<SE, E> ExprKind<SE, E> {
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
mut map_under_binder: impl FnMut(&'a Label, &'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
self.map_ref_maybe_binder(|l, x| match l {
None => map_subexpr(x),
Some(l) => map_under_binder(l, x),
@@ -235,33 +218,30 @@ impl<SE, E> ExprKind<SE, E> {
pub fn map_ref<'a, SE2>(
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
self.map_ref_maybe_binder(|_, e| map_subexpr(e))
}
}
-impl<E> Expr<E> {
- pub fn as_ref(&self) -> &UnspannedExpr<E> {
+impl Expr {
+ pub fn as_ref(&self) -> &UnspannedExpr {
&self.kind
}
- pub fn kind(&self) -> &UnspannedExpr<E> {
+ pub fn kind(&self) -> &UnspannedExpr {
&self.kind
}
pub fn span(&self) -> Span {
self.span.clone()
}
- pub fn new(kind: UnspannedExpr<E>, span: Span) -> Self {
+ pub fn new(kind: UnspannedExpr, span: Span) -> Self {
Expr {
kind: Box::new(kind),
span,
}
}
- pub fn rewrap<E2>(&self, kind: UnspannedExpr<E2>) -> Expr<E2> {
+ pub fn rewrap(&self, kind: UnspannedExpr) -> Expr {
Expr {
kind: Box::new(kind),
span: self.span.clone(),
@@ -317,15 +297,15 @@ impl From<Label> for V {
}
}
-impl<Embed: PartialEq> std::cmp::PartialEq for Expr<Embed> {
+impl std::cmp::PartialEq for Expr {
fn eq(&self, other: &Self) -> bool {
self.kind == other.kind
}
}
-impl<Embed: Eq> std::cmp::Eq for Expr<Embed> {}
+impl std::cmp::Eq for Expr {}
-impl<Embed: std::hash::Hash> std::hash::Hash for Expr<Embed> {
+impl std::hash::Hash for Expr {
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs
index c09b8d4..fc90efd 100644
--- a/dhall/src/syntax/ast/visitor.rs
+++ b/dhall/src/syntax/ast/visitor.rs
@@ -10,11 +10,10 @@ use crate::syntax::*;
/// preventing exactly this ! So we have to be more clever. The visitor pattern allows us to have
/// only one mutable thing the whole time: the visitor itself. The visitor can then carry around
/// multiple closures or just one, and Rust is ok with either. See for example TraverseRefVisitor.
-pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized {
+pub trait ExprKindVisitor<'a, SE1, SE2>: Sized {
type Error;
fn visit_subexpr(&mut self, subexpr: &'a SE1) -> Result<SE2, Self::Error>;
- fn visit_embed(self, embed: &'a E1) -> Result<E2, Self::Error>;
fn visit_subexpr_under_binder(
mut self,
@@ -26,18 +25,18 @@ pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized {
fn visit(
self,
- input: &'a ExprKind<SE1, E1>,
- ) -> Result<ExprKind<SE2, E2>, Self::Error> {
+ input: &'a ExprKind<SE1>,
+ ) -> Result<ExprKind<SE2>, Self::Error> {
visit_ref(self, input)
}
}
-fn visit_ref<'a, V, SE1, SE2, E1, E2>(
+fn visit_ref<'a, V, SE1, SE2>(
mut v: V,
- input: &'a ExprKind<SE1, E1>,
-) -> Result<ExprKind<SE2, E2>, V::Error>
+ input: &'a ExprKind<SE1>,
+) -> Result<ExprKind<SE2>, V::Error>
where
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
fn vec<'a, T, U, Err, F: FnMut(&'a T) -> Result<U, Err>>(
x: &'a [T],
@@ -54,27 +53,27 @@ where
None => None,
})
}
- fn dupmap<'a, V, SE1, SE2, E1, E2, T>(
+ fn dupmap<'a, V, SE1, SE2, T>(
x: impl IntoIterator<Item = (&'a Label, &'a SE1)>,
mut v: V,
) -> Result<T, V::Error>
where
SE1: 'a,
T: FromIterator<(Label, SE2)>,
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
x.into_iter()
.map(|(k, x)| Ok((k.clone(), v.visit_subexpr(x)?)))
.collect()
}
- fn optdupmap<'a, V, SE1, SE2, E1, E2, T>(
+ fn optdupmap<'a, V, SE1, SE2, T>(
x: impl IntoIterator<Item = (&'a Label, &'a Option<SE1>)>,
mut v: V,
) -> Result<T, V::Error>
where
SE1: 'a,
T: FromIterator<(Label, Option<SE2>)>,
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
x.into_iter()
.map(|(k, x)| {
@@ -147,17 +146,15 @@ where
}
Assert(e) => Assert(v.visit_subexpr(e)?),
Import(i) => Import(i.traverse_ref(|e| v.visit_subexpr(e))?),
- Embed(a) => Embed(v.visit_embed(a)?),
})
}
pub struct TraverseRefMaybeBinderVisitor<F>(pub F);
-impl<'a, SE, E, SE2, Err, F> ExprKindVisitor<'a, SE, SE2, E, E>
+impl<'a, SE, SE2, Err, F> ExprKindVisitor<'a, SE, SE2>
for TraverseRefMaybeBinderVisitor<F>
where
SE: 'a,
- E: 'a + Clone,
F: FnMut(Option<&'a Label>, &'a SE) -> Result<SE2, Err>,
{
type Error = Err;
@@ -172,7 +169,4 @@ where
) -> Result<SE2, Self::Error> {
(self.0)(Some(label), subexpr)
}
- fn visit_embed(self, embed: &'a E) -> Result<E, Self::Error> {
- Ok(embed.clone())
- }
}