Skip to content

Commit

Permalink
should parse function with no params
Browse files Browse the repository at this point in the history
  • Loading branch information
glyh committed Sep 16, 2024
1 parent bb22d3b commit 20d5054
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/parser/parser.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ fn parser() -> PS {

// Type
let type_ref : Ref[PT] = { val: empty() }
type_ref.val = tok(@lex.UNIT_T).map(fn { _ => T::Unit }) +
tok(@lex.BOOL_T).map(fn { _ => T::Bool }) +
type_ref.val = tok(@lex.BOOL_T).map(fn { _ => T::Bool }) +
tok(@lex.INT_T).map(fn { _ => T::Int }) +
tok(@lex.DOUBLE_T).map(fn { _ => T::Double }) +
(
Expand All @@ -38,9 +37,10 @@ fn parser() -> PS {
) +
lift2(
fn(args, ret) { T::Fun(args, ret) },
tok(@lex.LPAREN) >> sep_list1(tok(@lex.COMMA), ref(type_ref)),
tok(@lex.LPAREN) >> sep_list(tok(@lex.COMMA), ref(type_ref)),
tok(@lex.RPAREN) >> tok(@lex.ARROW) >> ref(type_ref),
) +
tok(@lex.UNIT_T).map(fn { _ => T::Unit }) +
(
tok(@lex.LPAREN) >>
sep_list1(tok(@lex.COMMA), ref(type_ref)).map(
Expand Down
14 changes: 14 additions & 0 deletions src/parser/parser_test_inline.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ test "nested fns" {
,
)
}

test "no param fn type" {
let src =
#|fn wat() -> () -> Int {
#| fn a() { 1 };
#| a
#|};
inspect!(
parse_program(src),
content=
#|LetRec({name: ("wat", Fun([], Int)), args: [], body: LetRec({name: ("a", Var({val: None})), args: [], body: Int(1)}, Var("a"))}, Unit)
,
)
}
4 changes: 2 additions & 2 deletions test/test_src/nested_fns.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn no_ann() -> Unit {
fn main() { () };
fn main() { fn lol(){ {fn wat(){()}; 1} }; 3 };
fn a(u: Int, v: Int, w) -> Int {
fn init() { () };
fn b(x: Bool, y, z: Bool) {
Expand All @@ -15,7 +15,7 @@ fn no_ann() -> Unit {
-> ((Unit) -> Int) -> Int {
fn d(x: Bool, y: Int, z: Int) {
let _ = not(not(not(x)));
let _ = -----y <= y;
let _ = 3-----y <= y;
let _ = y == y;
let a = Array::make(10, 10);
a[1] = 2;
Expand Down

0 comments on commit 20d5054

Please sign in to comment.