From d1c97e405230b6616ef834cf38be351e566a228e Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Thu, 21 Aug 2025 12:35:37 +0300 Subject: feat: implemented coproducts according to tests --- src/parse/parsetree.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/parse') diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs index 081489d..575afc9 100644 --- a/src/parse/parsetree.rs +++ b/src/parse/parsetree.rs @@ -202,6 +202,14 @@ fn parse_type(s: &str) -> IResult<&str, Type> { let absp = take_while1(|c| "ABCDEFGHIJKLMNOPQRSTUVWXYZ".contains(c)) .map(|s: &str| VarType(s.to_string())); + let sump = ( + tag("("), multispace0, + tag("Sum"), multispace1, + parse_type, multispace1, + parse_type, multispace0, + tag(")") + ).map(|tup| sumtype(tup.4, tup.6)); + alt(( tag("Int") .map(|_| Integer), tag("Bool") .map(|_| Boolean), @@ -210,6 +218,7 @@ fn parse_type(s: &str) -> IResult<&str, Type> { tag("Let") .map(|_| LetType), tag("Type") .map(|_| TypeLit), tag("Nil") .map(|_| NilType), + sump, arrp, vecp, listp, -- cgit v1.2.3