From 881248d2c4f0b4556a23d671d355bb7258adf8bb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 17 Dec 2019 14:33:06 +0000 Subject: Rename syntax::core to syntax::ast --- dhall/src/syntax/ast/expr.rs | 377 ++++++++++++++++++++++++++++++++++++++ dhall/src/syntax/ast/import.rs | 130 +++++++++++++ dhall/src/syntax/ast/label.rs | 34 ++++ dhall/src/syntax/ast/map.rs | 394 ++++++++++++++++++++++++++++++++++++++++ dhall/src/syntax/ast/mod.rs | 12 ++ dhall/src/syntax/ast/span.rs | 81 +++++++++ dhall/src/syntax/ast/text.rs | 181 ++++++++++++++++++ dhall/src/syntax/ast/visitor.rs | 360 ++++++++++++++++++++++++++++++++++++ 8 files changed, 1569 insertions(+) create mode 100644 dhall/src/syntax/ast/expr.rs create mode 100644 dhall/src/syntax/ast/import.rs create mode 100644 dhall/src/syntax/ast/label.rs create mode 100644 dhall/src/syntax/ast/map.rs create mode 100644 dhall/src/syntax/ast/mod.rs create mode 100644 dhall/src/syntax/ast/span.rs create mode 100644 dhall/src/syntax/ast/text.rs create mode 100644 dhall/src/syntax/ast/visitor.rs (limited to 'dhall/src/syntax/ast') diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs new file mode 100644 index 0000000..5b9f401 --- /dev/null +++ b/dhall/src/syntax/ast/expr.rs @@ -0,0 +1,377 @@ +use crate::syntax::map::{DupTreeMap, DupTreeSet}; +use crate::syntax::visitor::{self, ExprFMutVisitor, ExprFVisitor}; +use crate::syntax::*; + +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, + } +} + +/// 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