diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-21 12:35:37 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-21 12:35:37 +0300 |
commit | d1c97e405230b6616ef834cf38be351e566a228e (patch) | |
tree | 7c75d9353b0b3cc9f08400c5d09e0b7552afc9c8 /src/parse | |
parent | a70dcaa949f41c585f9aea5e79f2550053d8e857 (diff) | |
download | myslip-d1c97e405230b6616ef834cf38be351e566a228e.tar.gz myslip-d1c97e405230b6616ef834cf38be351e566a228e.zip |
feat: implemented coproducts according to tests
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/parsetree.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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, |