From e355984c3c83f8288eac36023c361db869643367 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 20 Dec 2019 18:12:10 +0000 Subject: s/ExprF/ExprKind/ --- dhall/src/syntax/ast/expr.rs | 24 ++++++++++---------- dhall/src/syntax/ast/visitor.rs | 47 ++++++++++++++++++++------------------- dhall/src/syntax/binary/decode.rs | 12 +++++----- dhall/src/syntax/binary/encode.rs | 14 +++++++----- dhall/src/syntax/text/parser.rs | 2 +- dhall/src/syntax/text/printer.rs | 20 ++++++++--------- 6 files changed, 61 insertions(+), 58 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index 5b9f401..7ac342d 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -1,5 +1,5 @@ use crate::syntax::map::{DupTreeMap, DupTreeSet}; -use crate::syntax::visitor::{self, ExprFMutVisitor, ExprFVisitor}; +use crate::syntax::visitor::{self, ExprKindMutVisitor, ExprKindVisitor}; use crate::syntax::*; pub type Integer = isize; @@ -144,7 +144,7 @@ pub enum Builtin { #[derive(Debug, Clone)] pub struct Expr(Box<(RawExpr, Span)>); -pub type RawExpr = ExprF, Embed>; +pub type RawExpr = ExprKind, Embed>; impl std::cmp::PartialEq for Expr { fn eq(&self, other: &Self) -> bool { @@ -168,7 +168,7 @@ impl std::hash::Hash for Expr { // much more generic code and improves pattern-matching behind // smart pointers. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum ExprF { +pub enum ExprKind { Const(Const), /// `x` /// `x@n` @@ -231,12 +231,12 @@ pub enum ExprF { Embed(Embed), } -impl ExprF { +impl ExprKind { pub fn traverse_ref_with_special_handling_of_binders<'a, SE2, Err>( &'a self, visit_subexpr: impl FnMut(&'a SE) -> Result, visit_under_binder: impl FnOnce(&'a Label, &'a SE) -> Result, - ) -> Result, Err> + ) -> Result, Err> where E: Clone, { @@ -250,7 +250,7 @@ impl ExprF { fn traverse_ref<'a, SE2, Err>( &'a self, visit_subexpr: impl FnMut(&'a SE) -> Result, - ) -> Result, Err> + ) -> Result, Err> where E: Clone, { @@ -268,7 +268,7 @@ impl ExprF { &'a self, mut map_subexpr: impl FnMut(&'a SE) -> SE2, mut map_under_binder: impl FnMut(&'a Label, &'a SE) -> SE2, - ) -> ExprF + ) -> ExprKind where E: Clone, { @@ -281,7 +281,7 @@ impl ExprF { pub fn map_ref<'a, SE2>( &'a self, mut map_subexpr: impl FnMut(&'a SE) -> SE2, - ) -> ExprF + ) -> ExprKind where E: Clone, { @@ -321,8 +321,8 @@ impl Expr { F1: FnMut(Import>) -> Result, { match self.as_mut() { - ExprF::BinOp(BinOp::ImportAlt, l, r) => { - let garbage_expr = ExprF::BoolLit(false); + ExprKind::BinOp(BinOp::ImportAlt, l, r) => { + let garbage_expr = ExprKind::BoolLit(false); let new_self = if l.traverse_resolve_mut(f).is_ok() { l } else { @@ -334,7 +334,7 @@ impl Expr { } _ => { self.as_mut().traverse_mut(|e| e.traverse_resolve_mut(f))?; - if let ExprF::Import(import) = self.as_mut() { + if let ExprKind::Import(import) = self.as_mut() { let garbage_import = Import { mode: ImportMode::Code, location: ImportLocation::Missing, @@ -342,7 +342,7 @@ impl Expr { }; // Move out of &mut import let import = std::mem::replace(import, garbage_import); - *self.as_mut() = ExprF::Embed(f(import)?); + *self.as_mut() = ExprKind::Embed(f(import)?); } } } diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs index b76d037..b557995 100644 --- a/dhall/src/syntax/ast/visitor.rs +++ b/dhall/src/syntax/ast/visitor.rs @@ -1,7 +1,7 @@ use crate::syntax::*; use std::iter::FromIterator; -/// A visitor trait that can be used to traverse `ExprF`s. We need this pattern so that Rust lets +/// A visitor trait that can be used to traverse `ExprKind`s. We need this pattern so that Rust lets /// us have as much mutability as we can. /// For example, `traverse_ref_with_special_handling_of_binders` cannot be made using only /// `traverse_ref`, because `traverse_ref` takes a `FnMut` so we would need to pass multiple @@ -9,7 +9,7 @@ use std::iter::FromIterator; /// 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 ExprFVisitor<'a, SE1, SE2, E1, E2>: Sized { +pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized { type Error; fn visit_subexpr(&mut self, subexpr: &'a SE1) -> Result; @@ -25,14 +25,14 @@ pub trait ExprFVisitor<'a, SE1, SE2, E1, E2>: Sized { fn visit( self, - input: &'a ExprF, - ) -> Result, Self::Error> { + input: &'a ExprKind, + ) -> Result, Self::Error> { visit_ref(self, input) } } -/// Like `ExprFVisitor`, but by mutable reference -pub trait ExprFMutVisitor<'a, SE, E>: Sized { +/// Like `ExprKindVisitor`, but by mutable reference +pub trait ExprKindMutVisitor<'a, SE, E>: Sized { type Error; fn visit_subexpr(&mut self, subexpr: &'a mut SE) @@ -49,17 +49,17 @@ pub trait ExprFMutVisitor<'a, SE, E>: Sized { self.visit_subexpr(subexpr) } - fn visit(self, input: &'a mut ExprF) -> Result<(), Self::Error> { + fn visit(self, input: &'a mut ExprKind) -> Result<(), Self::Error> { visit_mut(self, input) } } fn visit_ref<'a, V, SE1, SE2, E1, E2>( mut v: V, - input: &'a ExprF, -) -> Result, V::Error> + input: &'a ExprKind, +) -> Result, V::Error> where - V: ExprFVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, { fn vec<'a, T, U, Err, F: FnMut(&'a T) -> Result>( x: &'a [T], @@ -83,7 +83,7 @@ where where SE1: 'a, T: FromIterator<(Label, SE2)>, - V: ExprFVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, { x.into_iter() .map(|(k, x)| Ok((k.clone(), v.visit_subexpr(x)?))) @@ -96,7 +96,7 @@ where where SE1: 'a, T: FromIterator<(Label, Option)>, - V: ExprFVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, { x.into_iter() .map(|(k, x)| { @@ -111,7 +111,7 @@ where .collect() } - use crate::syntax::ExprF::*; + use crate::syntax::ExprKind::*; Ok(match input { Var(v) => Var(v.clone()), Lam(l, t, e) => { @@ -172,14 +172,14 @@ where fn visit_mut<'a, V, SE, E>( mut v: V, - input: &'a mut ExprF, + input: &'a mut ExprKind, ) -> Result<(), V::Error> where - V: ExprFMutVisitor<'a, SE, E>, + V: ExprKindMutVisitor<'a, SE, E>, { fn vec<'a, V, SE, E>(v: &mut V, x: &'a mut Vec) -> Result<(), V::Error> where - V: ExprFMutVisitor<'a, SE, E>, + V: ExprKindMutVisitor<'a, SE, E>, { for x in x { v.visit_subexpr(x)?; @@ -191,7 +191,7 @@ where x: &'a mut Option, ) -> Result<(), V::Error> where - V: ExprFMutVisitor<'a, SE, E>, + V: ExprKindMutVisitor<'a, SE, E>, { if let Some(x) = x { v.visit_subexpr(x)?; @@ -204,7 +204,7 @@ where ) -> Result<(), V::Error> where SE: 'a, - V: ExprFMutVisitor<'a, SE, E>, + V: ExprKindMutVisitor<'a, SE, E>, { for (_, x) in x { v.visit_subexpr(x)?; @@ -217,7 +217,7 @@ where ) -> Result<(), V::Error> where SE: 'a, - V: ExprFMutVisitor<'a, SE, E>, + V: ExprKindMutVisitor<'a, SE, E>, { for (_, x) in x { opt(&mut v, x)?; @@ -225,7 +225,7 @@ where Ok(()) } - use crate::syntax::ExprF::*; + use crate::syntax::ExprKind::*; match input { Var(_) | Const(_) | Builtin(_) | BoolLit(_) | NaturalLit(_) | IntegerLit(_) | DoubleLit(_) => {} @@ -293,7 +293,7 @@ pub struct TraverseRefWithBindersVisitor { pub visit_under_binder: F2, } -impl<'a, SE, E, SE2, Err, F1, F2> ExprFVisitor<'a, SE, SE2, E, E> +impl<'a, SE, E, SE2, Err, F1, F2> ExprKindVisitor<'a, SE, SE2, E, E> for TraverseRefWithBindersVisitor where SE: 'a, @@ -322,7 +322,7 @@ pub struct TraverseRefVisitor { pub visit_subexpr: F1, } -impl<'a, SE, E, SE2, Err, F1> ExprFVisitor<'a, SE, SE2, E, E> +impl<'a, SE, E, SE2, Err, F1> ExprKindVisitor<'a, SE, SE2, E, E> for TraverseRefVisitor where SE: 'a, @@ -343,7 +343,8 @@ pub struct TraverseMutVisitor { pub visit_subexpr: F1, } -impl<'a, SE, E, Err, F1> ExprFMutVisitor<'a, SE, E> for TraverseMutVisitor +impl<'a, SE, E, Err, F1> ExprKindMutVisitor<'a, SE, E> + for TraverseMutVisitor where SE: 'a, E: 'a, diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs index f452666..8b73e46 100644 --- a/dhall/src/syntax/binary/decode.rs +++ b/dhall/src/syntax/binary/decode.rs @@ -6,7 +6,7 @@ use crate::error::DecodeError; use crate::semantics::phase::DecodedExpr; use crate::syntax; use crate::syntax::{ - Expr, ExprF, FilePath, FilePrefix, Hash, ImportLocation, ImportMode, + Expr, ExprKind, FilePath, FilePrefix, Hash, ImportLocation, ImportMode, Integer, InterpolatedText, Label, Natural, RawExpr, Scheme, Span, URL, V, }; @@ -25,10 +25,10 @@ fn rc(x: RawExpr) -> Expr { fn cbor_value_to_dhall(data: &cbor::Value) -> Result { use cbor::Value::*; use syntax::{BinOp, Builtin, Const}; - use ExprF::*; + use ExprKind::*; Ok(rc(match data { String(s) => match Builtin::parse(s) { - Some(b) => ExprF::Builtin(b), + Some(b) => ExprKind::Builtin(b), None => match s.as_str() { "True" => BoolLit(true), "False" => BoolLit(false), @@ -123,7 +123,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result { } [U64(4), t] => { let t = cbor_value_to_dhall(&t)?; - EmptyListLit(rc(App(rc(ExprF::Builtin(Builtin::List)), t))) + EmptyListLit(rc(App(rc(ExprKind::Builtin(Builtin::List)), t))) } [U64(4), Null, rest @ ..] => { let rest = rest @@ -139,14 +139,14 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result { // Old-style optional literals [U64(5), t] => { let t = cbor_value_to_dhall(&t)?; - App(rc(ExprF::Builtin(Builtin::OptionalNone)), t) + App(rc(ExprKind::Builtin(Builtin::OptionalNone)), t) } [U64(5), t, x] => { let x = cbor_value_to_dhall(&x)?; let t = cbor_value_to_dhall(&t)?; Annot( rc(SomeLit(x)), - rc(App(rc(ExprF::Builtin(Builtin::Optional)), t)), + rc(App(rc(ExprKind::Builtin(Builtin::Optional)), t)), ) } [U64(6), x, y] => { diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs index c1e7c4c..25a545c 100644 --- a/dhall/src/syntax/binary/encode.rs +++ b/dhall/src/syntax/binary/encode.rs @@ -5,8 +5,8 @@ use crate::error::EncodeError; use crate::syntax; use crate::syntax::map::DupTreeMap; use crate::syntax::{ - Expr, ExprF, FilePrefix, Hash, Import, ImportLocation, ImportMode, Label, - Scheme, V, + Expr, ExprKind, FilePrefix, Hash, Import, ImportLocation, ImportMode, + Label, Scheme, V, }; /// Warning: will fail if `expr` contains an `Embed` node. @@ -46,7 +46,7 @@ where use cbor::Value::{String, I64, U64}; use std::iter::once; use syntax::Builtin; - use syntax::ExprF::*; + use syntax::ExprKind::*; use self::Serialize::{RecordMap, UnionMap}; fn expr(x: &Expr) -> self::Serialize<'_, E> { @@ -110,7 +110,9 @@ where SomeLit(x) => ser_seq!(ser; tag(5), null(), expr(x)), EmptyListLit(x) => match x.as_ref() { App(f, a) => match f.as_ref() { - ExprF::Builtin(Builtin::List) => ser_seq!(ser; tag(4), expr(a)), + ExprKind::Builtin(Builtin::List) => { + ser_seq!(ser; tag(4), expr(a)) + } _ => ser_seq!(ser; tag(28), expr(x)), }, _ => ser_seq!(ser; tag(28), expr(x)), @@ -284,7 +286,7 @@ fn collect_nested_applications<'a, E>( ) -> (&'a Expr, Vec<&'a Expr>) { fn go<'a, E>(e: &'a Expr, vec: &mut Vec<&'a Expr>) -> &'a Expr { match e.as_ref() { - ExprF::App(f, a) => { + ExprKind::App(f, a) => { vec.push(a); go(f, vec) } @@ -306,7 +308,7 @@ fn collect_nested_lets<'a, E>( vec: &mut Vec>, ) -> &'a Expr { match e.as_ref() { - ExprF::Let(l, t, v, e) => { + ExprKind::Let(l, t, v, e) => { vec.push((l, t, v)); go(e, vec) } diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 617348b..e1bb469 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -8,7 +8,7 @@ use pest_consume::{match_nodes, Parser}; use crate::semantics::phase::Normalized; use crate::syntax; use crate::syntax::map::{DupTreeMap, DupTreeSet}; -use crate::syntax::ExprF::*; +use crate::syntax::ExprKind::*; use crate::syntax::{ Double, FilePath, FilePrefix, Hash, ImportLocation, ImportMode, Integer, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble, Natural, diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 7ccc708..75703d2 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -3,9 +3,9 @@ use itertools::Itertools; use std::fmt::{self, Display}; /// Generic instance that delegates to subexpressions -impl Display for ExprF { +impl Display for ExprKind { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use crate::syntax::ExprF::*; + use crate::syntax::ExprKind::*; match self { Lam(a, b, c) => { write!(f, "λ({} : {}) → {}", a, b, c)?; @@ -53,10 +53,10 @@ impl Display for ExprF { Assert(a) => { write!(f, "assert : {}", a)?; } - ExprF::BinOp(op, a, b) => { + ExprKind::BinOp(op, a, b) => { write!(f, "{} {} {}", a, op, b)?; } - ExprF::App(a, b) => { + ExprKind::App(a, b) => { write!(f, "{} {}", a, b)?; } Field(a, b) => { @@ -141,7 +141,7 @@ impl RawExpr { f: &mut fmt::Formatter, phase: PrintPhase, ) -> Result<(), fmt::Error> { - use crate::syntax::ExprF::*; + use crate::syntax::ExprKind::*; use PrintPhase::*; let needs_paren = match self { @@ -160,8 +160,8 @@ impl RawExpr { true } // Precedence is magically handled by the ordering of BinOps. - ExprF::BinOp(op, _, _) if phase > PrintPhase::BinOp(*op) => true, - ExprF::App(_, _) if phase > PrintPhase::App => true, + ExprKind::BinOp(op, _, _) if phase > PrintPhase::BinOp(*op) => true, + ExprKind::App(_, _) if phase > PrintPhase::App => true, Field(_, _) | Projection(_, _) | ProjectionByExpr(_, _) if phase > PrintPhase::Import => { @@ -189,13 +189,13 @@ impl RawExpr { b.map(|x| x.phase(PrintPhase::App)), ), Annot(a, b) => Annot(a.phase(Operator), b), - ExprF::BinOp(op, a, b) => ExprF::BinOp( + ExprKind::BinOp(op, a, b) => ExprKind::BinOp( op, a.phase(PrintPhase::BinOp(op)), b.phase(PrintPhase::BinOp(op)), ), SomeLit(e) => SomeLit(e.phase(PrintPhase::Import)), - ExprF::App(f, a) => ExprF::App( + ExprKind::App(f, a) => ExprKind::App( f.phase(PrintPhase::Import), a.phase(PrintPhase::Import), ), @@ -209,7 +209,7 @@ impl RawExpr { f.write_str("(")?; } - // Uses the ExprF, _> instance + // Uses the ExprKind, _> instance phased_self.fmt(f)?; if needs_paren { -- cgit v1.2.3