#![allow(non_snake_case)] use std::collections::BTreeMap; use std::fmt::{self, Display}; use std::hash::Hash; use std::path::PathBuf; /// Constants for a pure type system /// /// The only axiom is: /// /// ```c /// ⊦ Type : Kind /// ``` /// /// ... and the valid rule pairs are: /// /// ```c /// ⊦ Type ↝ Type : Type -- Functions from terms to terms (ordinary functions) /// ⊦ Kind ↝ Type : Type -- Functions from types to terms (polymorphic functions) /// ⊦ Kind ↝ Kind : Kind -- Functions from types to types (type constructors) /// ``` /// /// These are the same rule pairs as System Fω /// /// Note that Dhall does not support functions from terms to types and therefore /// Dhall is not a dependently typed language /// #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Const { Type, 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<()>, } /// Label for a bound variable /// /// The `String` field is the variable's name (i.e. \"`x`\"). /// /// The `Int` field disambiguates variables with the same name if there are /// multiple bound variables of the same name in scope. Zero refers to the /// nearest bound variable and the index increases by one for each bound /// variable of the same name going outward. The following diagram may help: /// /// ```c /// +---refers to--+ /// | | /// v | /// \(x : Type) -> \(y : Type) -> \(x : Type) -> x@0 /// /// +------------------refers to-----------------+ /// | | /// v | /// \(x : Type) -> \(y : Type) -> \(x : Type) -> x@1 /// ``` /// /// This `Int` behaves like a De Bruijn index in the special case where all /// variables have the same name. /// /// You can optionally omit the index if it is `0`: /// /// ```c /// +refers to+ /// | | /// v | /// \(x : *) -> \(y : *) -> \(x : *) -> x /// ``` /// /// Zero indices are omitted when pretty-printing `Var`s and non-zero indices /// appear as a numeric suffix. /// #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct V