From 7bbf42dc5d3727dffcb036ffe30dd433faff1950 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 15:11:55 +0100 Subject: Reorganize dhall_core a bit --- dhall_core/src/core.rs | 682 +++------------------------------- dhall_core/src/lib.rs | 13 +- dhall_core/src/parser.rs | 923 ++++++++++++++++++++++++----------------------- 3 files changed, 539 insertions(+), 1079 deletions(-) (limited to 'dhall_core/src') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index e7c9f2a..68e781d 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -1,11 +1,17 @@ #![allow(non_snake_case)] +use crate::*; use std::collections::BTreeMap; -use std::fmt::{self, Display}; -use std::iter::FromIterator; -use std::ops::Add; -use std::path::PathBuf; use std::rc::Rc; +pub type Double = f64; +pub type Int = isize; +pub type Integer = isize; +pub type Natural = usize; + +/// An empty type +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum X {} + /// Constants for a pure type system /// /// The only axiom is: @@ -33,82 +39,9 @@ pub enum Const { Kind, } -/// The beginning of a file path which anchors subsequent path components -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum FilePrefix { - /// Absolute path - Absolute, - /// Path relative to . - Here, - /// Path relative to .. - Parent, - /// Path relative to ~ - Home, -} - -/// The location of import (i.e. local vs. remote vs. environment) -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ImportLocation { - Local(FilePrefix, PathBuf), - // TODO: other import types -} - -/// How to interpret the import's contents (i.e. as Dhall code or raw text) -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ImportMode { - Code, - // TODO - // RawText, -} - -/// Reference to an external resource -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Import { - pub mode: ImportMode, - pub location: ImportLocation, - // TODO - pub hash: Option<()>, -} - -// The type for labels throughout the AST -// It owns the data because otherwise lifetimes would make recursive imports impossible -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct Label(Rc); - -impl From for Label { - fn from(s: String) -> Self { - let s: &str = &s; - Label(s.into()) - } -} - -impl<'a> From<&'a str> for Label { - fn from(s: &'a str) -> Self { - Label(Rc::from(s)) - } -} - -impl From