From 8f874e056023a9f91b59a8731ea5ce020904da39 Mon Sep 17 00:00:00 2001 From: NanoTech Date: Tue, 6 Dec 2016 04:16:26 -0600 Subject: Parse builtins correctly --- src/grammar.lalrpop | 2 +- src/grammar_util.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') 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(<>)), "(" ")", }; 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>; pub type ExprOpFn = fn(BoxExpr, BoxExpr) -> Expr<(), ()>; @@ -6,3 +7,28 @@ pub type ExprOpFn = fn(BoxExpr, BoxExpr) -> Expr<(), ()>; pub fn bx(x: T) -> Box { Box::new(x) } + +pub fn builtin_expr(b: Builtin) -> Expr { + 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, + } +} -- cgit v1.2.3