From e2a3aea4516425ddb2022a85a3d492c605f910d4 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 20 Mar 2021 15:08:55 -0400 Subject: feat(gs/achilles): Prefix top-level ascriptions with `ty` This makes parsing less ambiguous, which is nice (we can continue to not actually care about indentation!) and aligns nicely with `fn` for the declaration itself. Change-Id: Id48f064e2a1e01c5105297be355d0991b312b76d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2615 Tested-by: BuildkiteCI Reviewed-by: glittershark --- users/glittershark/achilles/ach/functions.ach | 5 +++++ users/glittershark/achilles/src/parser/mod.rs | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/users/glittershark/achilles/ach/functions.ach b/users/glittershark/achilles/ach/functions.ach index 0d2f07eff574..dc6e7a1f3e34 100644 --- a/users/glittershark/achilles/ach/functions.ach +++ b/users/glittershark/achilles/ach/functions.ach @@ -1,3 +1,8 @@ +ty id : fn a -> a fn id x = x + +ty plus : fn int -> int fn plus (x: int) (y: int) = x + y + +ty main : fn -> int fn main = plus (id 2) 7 diff --git a/users/glittershark/achilles/src/parser/mod.rs b/users/glittershark/achilles/src/parser/mod.rs index c7e541ce48a0..652b083fdae5 100644 --- a/users/glittershark/achilles/src/parser/mod.rs +++ b/users/glittershark/achilles/src/parser/mod.rs @@ -22,6 +22,7 @@ pub(crate) fn is_reserved(s: &str) -> bool { | "let" | "in" | "fn" + | "ty" | "int" | "float" | "bool" @@ -115,11 +116,14 @@ named!(fun_decl(&str) -> Decl, do_parse!( )); named!(ascription_decl(&str) -> Decl, do_parse!( - name: ident + complete!(tag!("ty")) + >> multispace1 + >> name: ident >> multispace0 >> complete!(char!(':')) >> multispace0 >> type_: type_ + >> multispace0 >> (Decl::Ascription { name, type_ @@ -199,7 +203,7 @@ mod tests { #[test] fn top_level_ascription() { - let res = test_parse!(toplevel, "id : fn a -> a"); + let res = test_parse!(toplevel, "ty id : fn a -> a"); assert_eq!( res, vec![Decl::Ascription { -- cgit 1.4.1