use std::rc::Rc; use crate::map::{DupTreeMap, DupTreeSet}; use crate::visitor; use crate::*; pub type Integer = isize; pub type Natural = usize; pub type Double = NaiveDouble; pub fn trivial_result(x: Result) -> T { match x { Ok(x) => x, Err(e) => e, } } /// A location in the source text #[derive(Debug, Clone)] pub struct Span { input: Rc, /// # Safety /// /// Must be a valid character boundary index into `input`. start: usize, /// # Safety /// /// Must be a valid character boundary index into `input`. end: usize, } impl Span { pub(crate) fn make(input: Rc, sp: pest::Span) -> Self { Span { input, start: sp.start(), end: sp.end(), } } } /// 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 std::hash::Hash for NaiveDouble { fn hash(&self, state: &mut H) where H: std::hash::Hasher, { self.0.to_bits().hash(state) } } 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, PartialOrd, Ord, Hash)] 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, Hash)] pub struct V