summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/expr.rs22
-rw-r--r--dhall/src/syntax/ast/visitor.rs5
2 files changed, 15 insertions, 12 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 512010a..18ec9fd 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -103,6 +103,19 @@ pub struct Expr {
pub type UnspannedExpr = ExprKind<Expr>;
+/// Simple literals
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum LitKind {
+ /// `True`
+ Bool(bool),
+ /// `1`
+ Natural(Natural),
+ /// `+2`
+ Integer(Integer),
+ /// `3.24`
+ Double(Double),
+}
+
/// Syntax tree for expressions
// Having the recursion out of the enum definition enables writing
// much more generic code and improves pattern-matching behind
@@ -110,6 +123,7 @@ pub type UnspannedExpr = ExprKind<Expr>;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExprKind<SubExpr> {
Const(Const),
+ Lit(LitKind),
/// `x`
/// `x@n`
Var(V),
@@ -131,16 +145,8 @@ pub enum ExprKind<SubExpr> {
Builtin(Builtin),
// Binary operations
BinOp(BinOp, SubExpr, SubExpr),
- /// `True`
- BoolLit(bool),
/// `if x then y else z`
BoolIf(SubExpr, SubExpr, SubExpr),
- /// `1`
- NaturalLit(Natural),
- /// `+2`
- IntegerLit(Integer),
- /// `3.24`
- DoubleLit(Double),
/// `"Some ${interpolated} text"`
TextLit(InterpolatedText<SubExpr>),
/// `[] : t`
diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs
index 39959ac..c361bc1 100644
--- a/dhall/src/syntax/ast/visitor.rs
+++ b/dhall/src/syntax/ast/visitor.rs
@@ -91,10 +91,7 @@ where
Annot(x, t) => Annot(expr!(x)?, expr!(t)?),
Const(k) => Const(*k),
Builtin(v) => Builtin(*v),
- BoolLit(b) => BoolLit(*b),
- NaturalLit(n) => NaturalLit(*n),
- IntegerLit(n) => IntegerLit(*n),
- DoubleLit(n) => DoubleLit(*n),
+ Lit(l) => Lit(l.clone()),
TextLit(t) => TextLit(t.traverse_ref(|e| expr!(e))?),
BinOp(o, x, y) => BinOp(*o, expr!(x)?, expr!(y)?),
BoolIf(b, t, f) => BoolIf(expr!(b)?, expr!(t)?, expr!(f)?),