summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanoTech2016-12-06 04:16:26 -0600
committerNanoTech2017-03-10 23:48:27 -0600
commit8f874e056023a9f91b59a8731ea5ce020904da39 (patch)
tree60731da1da7950c9417cca4b2c0eec4c5fe6798e
parent7e76e6745ca2eb1dbe78c7503371094e6694fcdf (diff)
Parse builtins correctly
Diffstat (limited to '')
-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,
+ }
+}