aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-14 15:42:49 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-14 15:42:49 +0300
commit540a84fb9288699b534e98c8c5d0e649aaa1c2ba (patch)
tree9bdec40d723cd45232f21716c1d1c69c270fc065
parent928a3358483f60db84dc2918415882b35adc006b (diff)
downloadmyslip-540a84fb9288699b534e98c8c5d0e649aaa1c2ba.tar.gz
myslip-540a84fb9288699b534e98c8c5d0e649aaa1c2ba.zip
feat: added rest of types to the parser
also fixed function tests in check.rs
-rw-r--r--src/parse/parsetree.rs16
-rw-r--r--src/type/check.rs6
-rw-r--r--src/type/display.rs2
3 files changed, 16 insertions, 8 deletions
diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs
index 0a5782d..86da0f0 100644
--- a/src/parse/parsetree.rs
+++ b/src/parse/parsetree.rs
@@ -198,9 +198,13 @@ fn parse_type(s: &str) -> IResult<&str, Type> {
.map(|s: &str| VarType(s.to_string()));
alt((
- tag("Int").map(|_| Integer),
- tag("Bool").map(|_| Boolean),
- tag("Nil").map(|_| NilType),
+ tag("Int") .map(|_| Integer),
+ tag("Bool") .map(|_| Boolean),
+ tag("Quote") .map(|_| QuoteTy),
+ tag("Vector").map(|_| VecType),
+ tag("Let") .map(|_| LetType),
+ tag("Type") .map(|_| TypeLit),
+ tag("Nil") .map(|_| NilType),
arrp,
vecp,
listp,
@@ -217,7 +221,11 @@ mod private_parsing_tests {
fn test_parse_type() {
assert_eq!(parse_type("Int"), Ok(("", Integer)));
assert_eq!(parse_type("Bool"), Ok(("", Boolean)));
- assert_eq!(parse_type("Nil"), Ok(("", NilType)));
+ assert_eq!(parse_type("Quote"), Ok(("", QuoteTy)));
+ assert_eq!(parse_type("Vector"), Ok(("", VecType)));
+ assert_eq!(parse_type("Let"), Ok(("", LetType)));
+ assert_eq!(parse_type("Type"), Ok(("", TypeLit)));
+ assert_eq!(parse_type("Nil"), Ok(("", NilType)));
assert_eq!(parse_type("(Int -> Bool)"), Ok(("", arr(Integer, Boolean))));
assert_eq!(
parse_type("((Int -> Int) -> (Bool -> Bool))"),
diff --git a/src/type/check.rs b/src/type/check.rs
index ad6be13..2c04d2e 100644
--- a/src/type/check.rs
+++ b/src/type/check.rs
@@ -111,8 +111,8 @@ impl SExp {
/// };
///
/// let varlist = scons(var("a"), Nil);
- /// let typelist = scons(Ty(Integer), Nil);
- /// let ret = scons(Ty(Integer), Nil);
+ /// let typelist = Atom(Ty(Integer));
+ /// let ret = Atom(Ty(Integer));
/// let body = scons(Add, scons(var("a"), scons(1, Nil)));
/// assert_eq!(
/// scons(Fun, scons(varlist, scons(typelist, scons(ret, scons(body, Nil))))).type_check(),
@@ -127,7 +127,7 @@ impl SExp {
/// };
///
/// let varlist = scons(var("a"), scons(var("b"), Nil));
- /// let typelist = scons(Ty(List(vec![Integer])), Nil);
+ /// let typelist = Atom(Ty(List(vec![Integer, Integer])));
/// let ret = Atom(Ty(Boolean));
/// let body = scons(Eq, varlist.clone());
/// assert_eq!(
diff --git a/src/type/display.rs b/src/type/display.rs
index 27f1427..b562d7b 100644
--- a/src/type/display.rs
+++ b/src/type/display.rs
@@ -32,7 +32,7 @@ impl fmt::Display for Type {
VecType => write!(f, "{}", "Vector"),
LetType => write!(f, "{}", "Let"),
NilType => write!(f, "Nil"),
- TypeLit => write!(f, "[type literal]"),
+ TypeLit => write!(f, "Type"),
VecOf(ty) => write!(f, "({} ...)", *ty),
Arrow(a, b) => write!(f, "({} -> {})", a, b),
List(types) => write!(