summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grammar.lalrpop2
-rw-r--r--src/grammar_util.rs26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop
index 73d1675..8a4ad83 100644
--- a/src/grammar.lalrpop
+++ b/src/grammar.lalrpop
@@ -97,7 +97,7 @@ ExprF: BoxExpr = {
Nat => bx(NaturalLit(<>)),
Int => bx(IntegerLit(<>)),
Label => bx(Var(core::Var(<>, 0))), // FIXME support var@n syntax
- Builtin => bx(Bool), // FIXME
+ Builtin => bx(builtin_expr(<>)),
Bool => bx(BoolLit(<>)),
"(" <Expr> ")",
};
diff --git a/src/grammar_util.rs b/src/grammar_util.rs
index cbd1e59..d73be94 100644
--- a/src/grammar_util.rs
+++ b/src/grammar_util.rs
@@ -1,4 +1,5 @@
use core::Expr;
+use lexer::Builtin;
pub type BoxExpr = Box<Expr<(), ()>>;
pub type ExprOpFn = fn(BoxExpr, BoxExpr) -> Expr<(), ()>;
@@ -6,3 +7,28 @@ pub type ExprOpFn = fn(BoxExpr, BoxExpr) -> Expr<(), ()>;
pub fn bx<T>(x: T) -> Box<T> {
Box::new(x)
}
+
+pub fn builtin_expr<S, A>(b: Builtin) -> Expr<S, A> {
+ match b {
+ Builtin::Natural => Expr::Natural,
+ Builtin::NaturalFold => Expr::NaturalFold,
+ Builtin::NaturalBuild => Expr::NaturalBuild,
+ Builtin::NaturalIsZero => Expr::NaturalIsZero,
+ Builtin::NaturalEven => Expr::NaturalEven,
+ Builtin::NaturalOdd => Expr::NaturalOdd,
+ Builtin::Integer => Expr::Integer,
+ Builtin::Double => Expr::Double,
+ Builtin::Text => Expr::Text,
+ Builtin::List => Expr::List,
+ Builtin::ListBuild => Expr::ListBuild,
+ Builtin::ListFold => Expr::ListFold,
+ Builtin::ListLength => Expr::ListLength,
+ Builtin::ListHead => Expr::ListHead,
+ Builtin::ListLast => Expr::ListLast,
+ Builtin::ListIndexed => Expr::ListIndexed,
+ Builtin::ListReverse => Expr::ListReverse,
+ Builtin::Optional => Expr::Optional,
+ Builtin::OptionalFold => Expr::OptionalFold,
+ Builtin::Bool => Expr::Bool,
+ }
+}