Skip to content

Commit 6e0848d

Browse files
feat: repl and file typechecker
1 parent 285985d commit 6e0848d

File tree

7 files changed

+342
-119
lines changed

7 files changed

+342
-119
lines changed

Cargo.lock

+27-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
[dependencies]
99
anyhow = { version = "*" }
1010
lalrpop-util = { version = "0.20.0", features = ["lexer", "unicode"] }
11+
colored = "2.1.0"
1112

1213
[build-dependencies]
1314
lalrpop = "0.20.0"

examples/example.hm

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
let id = fun x -> x;
2+
let unit = id ();
3+
let perform = fun x -> x ();
24

35
let true = fun x -> fun y -> x;
46
let false = fun x -> fun y -> y;
57
let if = fun b -> fun x -> fun y -> b x y;
8+
let add = fun m -> fun n -> fun f -> fun x -> m f (n f x);
69

7-
let zero = fun s -> fun z -> z;
8-
let succ = fun n -> fun s -> fun z -> s (n s z);
9-
10-
let one = succ zero;
11-
let two = succ one;
12-
let three = succ two;
13-
let four = succ three;
14-
let five = succ four;
15-
16-
let one_or_two = fun cond -> if cond one two

src/grammar.lalrpop

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ pub Stmt: Stmt = {
1010
"let" <x:Ident> "=" <e1:Expr> "in" <e2:Expr> ";" => Stmt::Def(x.clone(), Expr::Let(x, Box::new(e1), Box::new(e2))),
1111
};
1212

13+
pub Stmts: Vec<Stmt> = {
14+
<stmts:Stmt*> => stmts,
15+
};
16+
1317
Expr: Expr = {
1418
Terminal,
1519
<l:Terminal> <r:Expr> => Expr::Apply(Box::new(l), Box::new(r)),

0 commit comments

Comments
 (0)