Skip to content

Commit

Permalink
incr: simplify parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LighghtEeloo committed Feb 10, 2024
1 parent f408781 commit 55d0360
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
7 changes: 1 addition & 6 deletions zydeco-lang/src/surface/parse/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Declaration: Declaration = {
"alias" <name:NameDef<UpperId>> <params:TypePattern*> "=" <ty:Box<Sp<Type>>> "end" => Alias {
name, params, ty,
}.into(),
"define" <gen:GenLet> DefineEnd => Define(gen).into(),
"define" <gen:GenLet> "end" => Define(gen).into(),
"main" <entry:Sp<TermComputation>> "end" => Main {
entry,
}.into(),
Expand All @@ -60,11 +60,6 @@ UseDef: UseDef = {
}.into(),
};

DefineEnd: () = {
"end" => (),
";" => (),
};

DataBr: DataBr<CtorV, Sp<Type>> = {
"|" <ctorv:CtorV> <tys:SepByDelim<"(", ",", <Sp<Type>>, ")">> => {
DataBr { ctorv, tys }
Expand Down
25 changes: 12 additions & 13 deletions zydeco-lang/tests/check-only/iota.zy
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ data LList' (A : VType) where
| Cons(A, U(F(LList' A)))
end

def rec iota : Int -> F(LList' Int) = (
def rec iota : Int -> F(LList' Int) =
fn (i: Int) ->
do i+1 <- ! add i 1;
ret Cons(i, { ! iota i+1 })
);
end

def rec foldr : U(F(LList' Int)) -> U(Int -> U(OS) -> OS) -> U(OS) -> OS = (
fn ll f b ->
do llv <- ! ll;
match llv
| Nil() -> ! b
| Cons(a, ll) -> ! f a { ! foldr ll f b }
end
);
def rec fn foldr (ll: U(F(LList' Int))) (f: U(Int -> U OS -> OS)) (b: U OS) : OS =
do llv <- ! ll;
match llv
| Nil() -> ! b
| Cons(a, ll) -> ! f a { ! foldr ll f b }
end
end

def loopy = {
def fn loopy =
! foldr
{ ! iota 0 }
{ fn (x: Int) (b: U(OS)) ->
{ fn (x: Int) (b: U OS) ->
do next? <- ! int_lt x 10;
! write_int_line x b
}
{ ! panic "unreachable" }
};
end

main
! loopy
Expand Down
4 changes: 2 additions & 2 deletions zydeco-lang/tests/check-only/loop.zydeco
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def rec loop : OS = ! (loop : U(OS));
def rec loop : OS = ! (loop : U OS) end
main
! loop
end
end
28 changes: 18 additions & 10 deletions zydeco-lang/tests/nonzero-exit-code/choice.zy
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ data Path (A : VType) where
| Cons(A, Path A)
end

def beep : Choice (U OS -> OS) = L({ fn (k) ->
! write_line "0" k
});
def boop : Choice (U OS -> OS) = R({ fn (k) ->
! write_line "1" k
});
def beep : Choice (U OS -> OS) =
L({ fn (k) ->
! write_line "0" k
})
end
def boop : Choice (U OS -> OS) =
R({ fn (k) ->
! write_line "1" k
})
end

def tree : Tree String = Fork(Fork(Final("x"), Final("o")), Final("x"));
def path : Path (Choice (U OS -> OS)) = Cons(beep, Cons(boop, Nil()));
def tree : Tree String =
Fork(Fork(Final("x"), Final("o")), Final("x"))
end
def path : Path (Choice (U OS -> OS)) =
Cons(beep, Cons(boop, Nil()))
end

def rec walk : Tree String -> Path (Choice (U OS -> OS)) -> OS = fn t p -> (
def rec walk : Tree String -> Path (Choice (U OS -> OS)) -> OS = fn t p ->
match t
| Final(res) -> (
match p
Expand Down Expand Up @@ -51,7 +59,7 @@ def rec walk : Tree String -> Path (Choice (U OS -> OS)) -> OS = fn t p -> (
end
)
end
);
end

main
! walk tree path
Expand Down

0 comments on commit 55d0360

Please sign in to comment.