From 45be2ff1f5bb3d6e0faa098402adf985b3d5e7ca Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 4 May 2019 12:38:36 +0200 Subject: Rename dhall_core to dhall_syntax --- Cargo.lock | 26 +- Cargo.toml | 4 +- dhall/Cargo.toml | 2 +- dhall/src/binary.rs | 4 +- dhall/src/error.rs | 6 +- dhall/src/expr.rs | 4 +- dhall/src/imports.rs | 6 +- dhall/src/normalize.rs | 8 +- dhall/src/serde.rs | 2 +- dhall/src/traits/dynamic_type.rs | 2 +- dhall/src/traits/static_type.rs | 2 +- dhall/src/typecheck.rs | 28 +- dhall/tests/traits.rs | 2 +- dhall_core/Cargo.toml | 16 - dhall_core/src/context.rs | 80 ---- dhall_core/src/core.rs | 563 ---------------------- dhall_core/src/import.rs | 64 --- dhall_core/src/label.rs | 34 -- dhall_core/src/lib.rs | 28 -- dhall_core/src/parser.rs | 984 -------------------------------------- dhall_core/src/printer.rs | 498 ------------------- dhall_core/src/text.rs | 116 ----- dhall_core/src/visitor.rs | 667 -------------------------- dhall_generated_parser/src/lib.rs | 2 +- dhall_generator/Cargo.toml | 2 +- dhall_generator/src/derive.rs | 14 +- dhall_generator/src/quote.rs | 62 +-- dhall_syntax/Cargo.toml | 16 + dhall_syntax/src/context.rs | 80 ++++ dhall_syntax/src/core.rs | 563 ++++++++++++++++++++++ dhall_syntax/src/import.rs | 64 +++ dhall_syntax/src/label.rs | 34 ++ dhall_syntax/src/lib.rs | 28 ++ dhall_syntax/src/parser.rs | 984 ++++++++++++++++++++++++++++++++++++++ dhall_syntax/src/printer.rs | 498 +++++++++++++++++++ dhall_syntax/src/text.rs | 116 +++++ dhall_syntax/src/visitor.rs | 667 ++++++++++++++++++++++++++ 37 files changed, 3138 insertions(+), 3138 deletions(-) delete mode 100644 dhall_core/Cargo.toml delete mode 100644 dhall_core/src/context.rs delete mode 100644 dhall_core/src/core.rs delete mode 100644 dhall_core/src/import.rs delete mode 100644 dhall_core/src/label.rs delete mode 100644 dhall_core/src/lib.rs delete mode 100644 dhall_core/src/parser.rs delete mode 100644 dhall_core/src/printer.rs delete mode 100644 dhall_core/src/text.rs delete mode 100644 dhall_core/src/visitor.rs create mode 100644 dhall_syntax/Cargo.toml create mode 100644 dhall_syntax/src/context.rs create mode 100644 dhall_syntax/src/core.rs create mode 100644 dhall_syntax/src/import.rs create mode 100644 dhall_syntax/src/label.rs create mode 100644 dhall_syntax/src/lib.rs create mode 100644 dhall_syntax/src/parser.rs create mode 100644 dhall_syntax/src/printer.rs create mode 100644 dhall_syntax/src/text.rs create mode 100644 dhall_syntax/src/visitor.rs diff --git a/Cargo.lock b/Cargo.lock index ada5ea2..876e97c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,8 +69,8 @@ name = "dhall" version = "0.1.0" dependencies = [ "bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dhall_core 0.1.0", "dhall_generator 0.1.0", + "dhall_syntax 0.1.0", "improved_slice_patterns 2.0.0", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -80,17 +80,6 @@ dependencies = [ "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "dhall_core" -version = "0.1.0" -dependencies = [ - "dhall_generated_parser 0.1.0", - "improved_slice_patterns 2.0.0", - "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "dhall_generated_parser" version = "0.1.0" @@ -105,13 +94,24 @@ dependencies = [ name = "dhall_generator" version = "0.1.0" dependencies = [ - "dhall_core 0.1.0", + "dhall_syntax 0.1.0", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dhall_syntax" +version = "0.1.0" +dependencies = [ + "dhall_generated_parser 0.1.0", + "improved_slice_patterns 2.0.0", + "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "difference" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index 0474d20..7153910 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "abnf_to_pest", "dhall", "dhall_generated_parser", - "dhall_core", + "dhall_syntax", "dhall_generator", "improved_slice_patterns", ] @@ -13,7 +13,7 @@ members = [ # # Parser is super slow when not optimized # [profile.dev.overrides.dhall_parser] # opt-level = 3 -# [profile.dev.overrides.dhall_core] +# [profile.dev.overrides.dhall_syntax] # opt-level = 3 # [profile.dev.overrides.dhall] # opt-level = 3 diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index 637d511..28123e5 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -13,7 +13,7 @@ term-painter = "0.2.3" serde = { version = "1.0", features = ["derive"] } serde_cbor = "0.9.0" improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" } -dhall_core = { path = "../dhall_core" } +dhall_syntax = { path = "../dhall_syntax" } dhall_generator = { path = "../dhall_generator" } [dev-dependencies] diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs index cadd456..9c31d4c 100644 --- a/dhall/src/binary.rs +++ b/dhall/src/binary.rs @@ -1,4 +1,4 @@ -use dhall_core::*; +use dhall_syntax::*; use itertools::*; use serde_cbor::value::value as cbor; @@ -19,7 +19,7 @@ pub fn decode(data: &[u8]) -> Result { fn cbor_value_to_dhall(data: &cbor::Value) -> Result { use cbor::Value::*; - use dhall_core::{BinOp, Builtin, Const}; + use dhall_syntax::{BinOp, Builtin, Const}; use ExprF::*; Ok(rc(match data { String(s) => match Builtin::parse(s) { diff --git a/dhall/src/error.rs b/dhall/src/error.rs index b987165..6ed0bfb 100644 --- a/dhall/src/error.rs +++ b/dhall/src/error.rs @@ -4,7 +4,7 @@ pub type Result = std::result::Result; #[non_exhaustive] pub enum Error { IO(std::io::Error), - Parse(dhall_core::ParseError), + Parse(dhall_syntax::ParseError), Decode(crate::binary::DecodeError), Resolve(crate::imports::ImportError), Typecheck(crate::typecheck::TypeError), @@ -30,8 +30,8 @@ impl From for Error { Error::IO(err) } } -impl From for Error { - fn from(err: dhall_core::ParseError) -> Error { +impl From for Error { + fn from(err: dhall_syntax::ParseError) -> Error { Error::Parse(err) } } diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 9a161bd..b0b6215 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -1,6 +1,6 @@ use crate::imports::ImportRoot; use crate::normalize::{Thunk, Value}; -use dhall_core::*; +use dhall_syntax::*; use std::marker::PhantomData; macro_rules! derive_other_traits { @@ -71,7 +71,7 @@ mod typed { use crate::typecheck::{ TypeError, TypeInternal, TypeMessage, TypecheckContext, }; - use dhall_core::{Const, Label, SubExpr, V, X}; + use dhall_syntax::{Const, Label, SubExpr, V, X}; use std::borrow::Cow; use std::marker::PhantomData; diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index e367725..306d4e6 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -1,6 +1,6 @@ use crate::error::Error; use crate::expr::*; -use dhall_core::*; +use dhall_syntax::*; use std::collections::HashMap; use std::fs::File; use std::io::Read; @@ -31,8 +31,8 @@ fn resolve_import( import_stack: &ImportStack, ) -> Result, ImportError> { use self::ImportRoot::*; - use dhall_core::FilePrefix::*; - use dhall_core::ImportLocation::*; + use dhall_syntax::FilePrefix::*; + use dhall_syntax::ImportLocation::*; let cwd = match root { LocalDir(cwd) => cwd, }; diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 9327a34..c64bb4a 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -2,8 +2,8 @@ use std::collections::BTreeMap; use std::rc::Rc; -use dhall_core::context::Context; -use dhall_core::{ +use dhall_syntax::context::Context; +use dhall_syntax::{ rc, BinOp, Builtin, Const, ExprF, Integer, InterpolatedText, InterpolatedTextContents, Label, Natural, SubExpr, V, X, }; @@ -633,7 +633,7 @@ mod thunk { OutputSubExpr, Value, }; use crate::expr::Typed; - use dhall_core::{Label, V}; + use dhall_syntax::{Label, V}; use std::cell::{Ref, RefCell}; use std::rc::Rc; @@ -893,7 +893,7 @@ impl TypeThunk { } fn apply_builtin(b: Builtin, args: Vec) -> Value { - use dhall_core::Builtin::*; + use dhall_syntax::Builtin::*; use Value::*; // Return Ok((unconsumed args, returned value)), or Err(()) if value could not be produced. diff --git a/dhall/src/serde.rs b/dhall/src/serde.rs index 6f143cb..96bc765 100644 --- a/dhall/src/serde.rs +++ b/dhall/src/serde.rs @@ -1,7 +1,7 @@ use crate::error::{Error, Result}; use crate::expr::{Normalized, Type}; use crate::traits::Deserialize; -use dhall_core::*; +use dhall_syntax::*; use std::borrow::Cow; impl<'a, T: serde::Deserialize<'a>> Deserialize<'a> for T { diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/traits/dynamic_type.rs index 74c2e0a..b8f6f6d 100644 --- a/dhall/src/traits/dynamic_type.rs +++ b/dhall/src/traits/dynamic_type.rs @@ -3,7 +3,7 @@ use crate::traits::StaticType; #[allow(unused_imports)] use crate::typecheck::{TypeError, TypeMessage, TypecheckContext}; #[allow(unused_imports)] -use dhall_core::{Const, ExprF}; +use dhall_syntax::{Const, ExprF}; use std::borrow::Cow; pub trait DynamicType { diff --git a/dhall/src/traits/static_type.rs b/dhall/src/traits/static_type.rs index df6a177..6e42da8 100644 --- a/dhall/src/traits/static_type.rs +++ b/dhall/src/traits/static_type.rs @@ -1,5 +1,5 @@ use crate::expr::*; -use dhall_core::*; +use dhall_syntax::*; use dhall_generator as dhall; /// A value that has a statically-known Dhall type. diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 598ae1f..1683fbf 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -7,9 +7,9 @@ use std::fmt; use crate::expr::*; use crate::normalize::{NormalizationContext, Thunk, TypeThunk, Value}; use crate::traits::DynamicType; -use dhall_core; -use dhall_core::context::Context; -use dhall_core::*; +use dhall_syntax; +use dhall_syntax::context::Context; +use dhall_syntax::*; use dhall_generator as dhall; use self::TypeMessage::*; @@ -113,7 +113,7 @@ impl TypeThunk { } } -/// A semantic type. This is partially redundant with `dhall_core::Expr`, on purpose. `TypeInternal` should +/// A semantic type. This is partially redundant with `dhall_syntax::Expr`, on purpose. `TypeInternal` should /// be limited to syntactic expressions: either written by the user or meant to be printed. /// The rule is the following: we must _not_ construct values of type `Expr` while typechecking, /// but only construct `TypeInternal`s. @@ -245,7 +245,7 @@ impl PartialEq for TypecheckContext { impl Eq for TypecheckContext {} fn function_check(a: Const, b: Const) -> Result { - use dhall_core::Const::*; + use dhall_syntax::Const::*; match (a, b) { (_, Type) => Ok(Type), (Kind, Kind) => Ok(Kind), @@ -279,7 +279,7 @@ where T: Borrow>, U: Borrow>, { - use dhall_core::ExprF::*; + use dhall_syntax::ExprF::*; fn go<'a, S, T>( ctx: &mut Vec<(&'a Label, &'a Label)>, el: &'a SubExpr, @@ -368,7 +368,7 @@ fn type_of_const<'a>(c: Const) -> Result, TypeError> { } fn type_of_builtin(b: Builtin) -> Expr { - use dhall_core::Builtin::*; + use dhall_syntax::Builtin::*; match b { Bool | Natural | Integer | Double | Text => dhall::expr!(Type), List | Optional => dhall::expr!( @@ -464,7 +464,7 @@ macro_rules! ensure_equal { macro_rules! ensure_simple_type { ($x:expr, $err:expr $(,)*) => {{ match $x.get_type()?.as_const() { - Some(dhall_core::Const::Type) => {} + Some(dhall_syntax::Const::Type) => {} _ => return Err($err), } }}; @@ -553,7 +553,7 @@ impl TypeIntermediate { } } // An empty record type has type Type - let k = k.unwrap_or(dhall_core::Const::Type); + let k = k.unwrap_or(dhall_syntax::Const::Type); Typed::from_thunk_and_type( Value::RecordType( @@ -587,7 +587,7 @@ impl TypeIntermediate { // An empty union type has type Type; // an union type with only unary variants also has type Type - let k = k.unwrap_or(dhall_core::Const::Type); + let k = k.unwrap_or(dhall_syntax::Const::Type); Typed::from_thunk_and_type( Value::UnionType( @@ -664,7 +664,7 @@ fn type_with( ctx: &TypecheckContext, e: SubExpr>, ) -> Result, TypeError> { - use dhall_core::ExprF::*; + use dhall_syntax::ExprF::*; use Ret::*; let ret = match e.as_ref() { @@ -738,9 +738,9 @@ fn type_last_layer( ctx: &TypecheckContext, e: ExprF, Label, X, Normalized<'static>>, ) -> Result { - use dhall_core::BinOp::*; - use dhall_core::Builtin::*; - use dhall_core::ExprF::*; + use dhall_syntax::BinOp::*; + use dhall_syntax::Builtin::*; + use dhall_syntax::ExprF::*; let mkerr = |msg: TypeMessage<'static>| TypeError::new(ctx, msg); use Ret::*; diff --git a/dhall/tests/traits.rs b/dhall/tests/traits.rs index a7cd530..e26a6c7 100644 --- a/dhall/tests/traits.rs +++ b/dhall/tests/traits.rs @@ -1,6 +1,6 @@ #![feature(proc_macro_hygiene)] use dhall::de::SimpleStaticType; -use dhall_core::{SubExpr, X}; +use dhall_syntax::{SubExpr, X}; use dhall_generator; #[test] diff --git a/dhall_core/Cargo.toml b/dhall_core/Cargo.toml deleted file mode 100644 index 476b9fa..0000000 --- a/dhall_core/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "dhall_core" -version = "0.1.0" -authors = ["NanoTech ", "Nadrieril "] -license = "BSD-2-Clause" -edition = "2018" - -[lib] -doctest = false - -[dependencies] -itertools = "0.8.0" -percent-encoding = "1.0.1" -pest = "2.1" -dhall_generated_parser = { path = "../dhall_generated_parser" } -improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" } diff --git a/dhall_core/src/context.rs b/dhall_core/src/context.rs deleted file mode 100644 index 55bfff5..0000000 --- a/dhall_core/src/context.rs +++ /dev/null @@ -1,80 +0,0 @@ -use std::cmp::Eq; -use std::collections::HashMap; -use std::hash::Hash; - -/// A `(Context a)` associates `Text` labels with values of type `a` -/// -/// The `Context` is used for type-checking when `(a = Expr X)` -/// -/// * You create a `Context` using `empty` and `insert` -/// * You transform a `Context` using `fmap` -/// * You consume a `Context` using `lookup` and `toList` -/// -/// The difference between a `Context` and a `Map` is that a `Context` lets you -/// have multiple ordered occurrences of the same key and you can query for the -/// `n`th occurrence of a given key. -/// -#[derive(Debug, Clone)] -pub struct Context(HashMap>); - -impl Context { - /// An empty context with no key-value pairs - pub fn new() -> Self { - Context(HashMap::new()) - } - - /// Look up a key by name and index - /// - /// ```c - /// lookup _ _ empty = Nothing - /// lookup k 0 (insert k v c) = Just v - /// lookup k n (insert k v c) = lookup k (n - 1) c -- 1 <= n - /// lookup k n (insert j v c) = lookup k n c -- k /= j - /// ``` - pub fn lookup<'a>(&'a self, k: &K, n: usize) -> Option<&'a T> { - self.0.get(k).and_then(|v| { - if n < v.len() { - v.get(v.len() - 1 - n) - } else { - None - } - }) - } - - pub fn map U>(&self, f: F) -> Context { - Context( - self.0 - .iter() - .map(|(k, vs)| { - ((*k).clone(), vs.iter().map(|v| f(k, v)).collect()) - }) - .collect(), - ) - } - - pub fn lookup_all<'a>(&'a self, k: &K) -> impl Iterator { - self.0.get(k).into_iter().flat_map(|v| v.iter()) - } - - pub fn iter<'a>(&'a self) -> impl Iterator { - self.0 - .iter() - .flat_map(|(k, vs)| vs.iter().map(move |v| (k, v))) - } - - pub fn iter_keys<'a>(&'a self) -> impl Iterator)> { - self.0.iter() - } -} - -impl Context { - /// Add a key-value pair to the `Context` - pub fn insert(&self, k: K, v: T) -> Self { - let mut ctx = (*self).clone(); - { - let m = ctx.0.entry(k).or_insert_with(Vec::new); - m.push(v); - } - ctx - } -} diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs deleted file mode 100644 index 3db07dd..0000000 --- a/dhall_core/src/core.rs +++ /dev/null @@ -1,563 +0,0 @@ -#![allow(non_snake_case)] -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::rc::Rc; - -use crate::context::Context; -use crate::visitor; -use crate::*; - -pub type Integer = isize; -pub type Natural = usize; -pub type Double = NaiveDouble; - -/// An empty type -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum X {} - -pub fn trivial_result(x: Result) -> T { - match x { - Ok(x) => x, - Err(e) => match e {}, - } -} - -/// Double with bitwise equality -#[derive(Debug, Copy, Clone)] -pub struct NaiveDouble(f64); - -impl PartialEq for NaiveDouble { - fn eq(&self, other: &Self) -> bool { - self.0.to_bits() == other.0.to_bits() - } -} - -impl Eq for NaiveDouble {} - -impl From for NaiveDouble { - fn from(x: f64) -> Self { - NaiveDouble(x) - } -} - -impl From for f64 { - fn from(x: NaiveDouble) -> f64 { - x.0 - } -} - -/// Constants for a pure type system -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum Const { - Type, - Kind, - Sort, -} - -/// Bound variable -/// -/// 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, PartialEq, Eq)] -pub struct V