summaryrefslogtreecommitdiff
path: root/dhall/src/syntax
diff options
context:
space:
mode:
authorNadrieril2020-01-29 22:06:01 +0000
committerNadrieril2020-01-29 22:06:01 +0000
commita928c3c4f51d87fd942e8a81727962c00abf6808 (patch)
tree4351f1326814d7ba5ecd89d47a56c9f55be40fb5 /dhall/src/syntax
parent489174a426e6057a68b6edd2e9b4387d09912a25 (diff)
Cleanup variable handling
Diffstat (limited to 'dhall/src/syntax')
-rw-r--r--dhall/src/syntax/ast/expr.rs16
-rw-r--r--dhall/src/syntax/text/parser.rs2
-rw-r--r--dhall/src/syntax/text/printer.rs2
3 files changed, 7 insertions, 13 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 424ac34..28a0aee 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -23,8 +23,8 @@ pub enum Const {
/// The `Label` field is the variable's name (i.e. \"`x`\").
/// The `Int` field is a DeBruijn index.
/// See dhall-lang/standard/semantics.md for details
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub struct V<Label>(pub Label, pub usize);
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct V(pub Label, pub usize);
// Definition order must match precedence order for
// pretty-printing to work correctly
@@ -112,7 +112,7 @@ pub enum ExprKind<SubExpr, Embed> {
Const(Const),
/// `x`
/// `x@n`
- Var(V<Label>),
+ Var(V),
/// `λ(x : A) -> b`
Lam(Label, SubExpr, SubExpr),
/// `A -> B`
@@ -173,12 +173,6 @@ pub enum ExprKind<SubExpr, Embed> {
Embed(Embed),
}
-impl<Label> V<Label> {
- pub(crate) fn idx(&self) -> usize {
- self.1
- }
-}
-
impl<SE, E> ExprKind<SE, E> {
pub fn traverse_ref_maybe_binder<'a, SE2, Err>(
&'a self,
@@ -356,8 +350,8 @@ impl From<NaiveDouble> for f64 {
}
}
-impl<Label> From<Label> for V<Label> {
- fn from(x: Label) -> V<Label> {
+impl From<Label> for V {
+ fn from(x: Label) -> V {
V(x, 0)
}
}
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index ef1471f..681d6dd 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -422,7 +422,7 @@ impl DhallParser {
))
}
- fn variable(input: ParseInput) -> ParseResult<V<Label>> {
+ fn variable(input: ParseInput) -> ParseResult<V> {
Ok(match_nodes!(input.into_children();
[label(l), natural_literal(idx)] => V(l, idx),
[label(l)] => V(l, 0),
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 96f4c2a..06dd70f 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -496,7 +496,7 @@ impl Display for Scheme {
}
}
-impl<Label: Display> Display for V<Label> {
+impl Display for V {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let V(x, n) = self;
x.fmt(f)?;