summaryrefslogtreecommitdiff
path: root/dhall/src/core.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-03 00:37:16 +0100
committerNadrieril2019-03-03 00:37:16 +0100
commit5cd18f220a42d3d4072566b6e0424c5edf692860 (patch)
tree308ccece62521c7740de13c182bdd1bfe915752b /dhall/src/core.rs
parent3f19f1b34386875def0e6124fe550baefc81f65a (diff)
Parse builtins
Diffstat (limited to '')
-rw-r--r--dhall/src/core.rs50
1 files changed, 30 insertions, 20 deletions
diff --git a/dhall/src/core.rs b/dhall/src/core.rs
index c5b6d86..88eff36 100644
--- a/dhall/src/core.rs
+++ b/dhall/src/core.rs
@@ -184,46 +184,26 @@ pub enum Expr<'i, S, A> {
/// Built-ins
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Builtin {
- /// `Bool ~ Bool`
Bool,
- /// `Natural ~ Natural`
Natural,
- /// `Integer ~ Integer`
Integer,
- /// `Double ~ Double`
Double,
- /// `Text ~ Text`
Text,
- /// `List ~ List`
List,
- /// `Optional ~ Optional`
Optional,
- /// `NaturalFold ~ Natural/fold`
NaturalFold,
- /// `NaturalBuild ~ Natural/build`
NaturalBuild,
- /// `NaturalIsZero ~ Natural/isZero`
NaturalIsZero,
- /// `NaturalEven ~ Natural/even`
NaturalEven,
- /// `NaturalOdd ~ Natural/odd`
NaturalOdd,
NaturalShow,
- /// `ListBuild ~ List/build`
ListBuild,
- /// `ListFold ~ List/fold`
ListFold,
- /// `ListLength ~ List/length`
ListLength,
- /// `ListHead ~ List/head`
ListHead,
- /// `ListLast ~ List/last`
ListLast,
- /// `ListIndexed ~ List/indexed`
ListIndexed,
- /// `ListReverse ~ List/reverse`
ListReverse,
- /// `OptionalFold ~ Optional/fold`
OptionalFold,
}
@@ -474,6 +454,36 @@ impl Display for Builtin {
}
}
+impl Builtin {
+ pub fn parse(s: &str) -> Option<Self> {
+ use self::Builtin::*;
+ match s {
+ "Bool" => Some(Bool),
+ "Natural" => Some(Natural),
+ "Integer" => Some(Integer),
+ "Double" => Some(Double),
+ "Text" => Some(Text),
+ "List" => Some(List),
+ "Optional" => Some(Optional),
+ "Natural/fold" => Some(NaturalFold),
+ "Natural/build" => Some(NaturalBuild),
+ "Natural/isZero" => Some(NaturalIsZero),
+ "Natural/even" => Some(NaturalEven),
+ "Natural/odd" => Some(NaturalOdd),
+ "Natural/show" => Some(NaturalShow),
+ "List/build" => Some(ListBuild),
+ "List/fold" => Some(ListFold),
+ "List/length" => Some(ListLength),
+ "List/head" => Some(ListHead),
+ "List/last" => Some(ListLast),
+ "List/indexed" => Some(ListIndexed),
+ "List/reverse" => Some(ListReverse),
+ "Optional/fold" => Some(OptionalFold),
+ _ => None,
+ }
+ }
+}
+
impl<'i> Display for V<'i> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let V(x, n) = *self;