From 6cbe21b84ffd274f92791ab8dbf9af6527978688 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 20:30:25 +0100 Subject: oops --- dhall_core/src/import.rs | 38 ++++++ dhall_core/src/label.rs | 38 ++++++ dhall_core/src/printer.rs | 329 ++++++++++++++++++++++++++++++++++++++++++++++ dhall_core/src/text.rs | 92 +++++++++++++ 4 files changed, 497 insertions(+) create mode 100644 dhall_core/src/import.rs create mode 100644 dhall_core/src/label.rs create mode 100644 dhall_core/src/printer.rs create mode 100644 dhall_core/src/text.rs diff --git a/dhall_core/src/import.rs b/dhall_core/src/import.rs new file mode 100644 index 0000000..3e2fbe8 --- /dev/null +++ b/dhall_core/src/import.rs @@ -0,0 +1,38 @@ +use std::path::PathBuf; + +/// 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<()>, +} diff --git a/dhall_core/src/label.rs b/dhall_core/src/label.rs new file mode 100644 index 0000000..3633b93 --- /dev/null +++ b/dhall_core/src/label.rs @@ -0,0 +1,38 @@ +use std::fmt::{self, Display}; +use std::rc::Rc; + +// 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