diff --git a/README.md b/README.md index cf296db..fcaf42c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,13 @@ add2 4 // nested function calls add2 (sub4 (mul2 4)) + +// if is an expression that can return a value +let value = + if a == b then + a + else + b ``` ### Declarations diff --git a/src/grammar.pest b/src/grammar.pest index 768f9f1..051dbda 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -3,7 +3,7 @@ file = { } statement = { (decl | type_decl | expr) ~ TERMINATE } -decl = { "let" ~ #name = ident ~ #args = (ident)* ~ #type = type_annot? ~ "=" ~ expr } +decl = { "let" ~ #name = ident ~ #args = (ident)* ~ #type = type_annot? ~ "=" ~ MLF ~ expr } block = { "{" ~ MLF ~ block_line ~ MLF ~ "}" } block_line = _{ expr | (statement ~ MLF)* } diff --git a/tests/corpus/statements/if-stmt.txt b/tests/corpus/statements/if-stmt.txt index d38f8b5..6ecbbfb 100644 --- a/tests/corpus/statements/if-stmt.txt +++ b/tests/corpus/statements/if-stmt.txt @@ -12,6 +12,12 @@ if 1 != 1 then { a + 1 } +let value = + if a == b then + a + else + b + ====== (file @@ -88,5 +94,27 @@ if 1 != 1 then { ) ) ) + (statement + (decl + (ident: "value") + (expr + (if + (expr + (infix_expr + (ident: "a") + (operator: "==") + (ident: "b") + ) + ) + (expr + (ident: "a") + ) + (expr + (ident: "b") + ) + ) + ) + ) + ) (EOI: "") )