diff --git a/SYNTAX.md b/SYNTAX.md index d9db498..f092a1c 100644 --- a/SYNTAX.md +++ b/SYNTAX.md @@ -70,7 +70,7 @@ Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-or ```sml case 1 + 1 of | 2 -> @write("Yes"); - \ @write("How?"); + | else @write("How?"); end; ``` 10) Do notation. It allows you to have multiple expression because something like right hand side of the function declaration `fun a: int = ...` can only have 1 expression. Do allows you to bypass that. @@ -89,4 +89,4 @@ fun main: void = do @write("Hello, World"); @write(34 + 35); end; -``` \ No newline at end of file +``` diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 37b7359..d8d14f9 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -70,8 +70,8 @@ impl std::fmt::Display for IRKind { ) }, IRKind::Fun { ref public, ref name, ref return_type_hint, ref args, ref body } => { - write!(f, "(fun{} {} {} {} {})", - if *public { "export" } else { "" }, + write!(f, "(fun{} {} :{} [{}] {})", + if *public { " export" } else { "" }, name, return_type_hint, args.iter().map(|(name, type_hint)| format!(":{} {}", name, type_hint)).collect::>().join(" "), diff --git a/crates/lexer/src/lib.rs b/crates/lexer/src/lib.rs index c42ceac..30c074f 100644 --- a/crates/lexer/src/lib.rs +++ b/crates/lexer/src/lib.rs @@ -16,7 +16,7 @@ pub enum Token { // Operators Plus, Minus, Multiply, Divide, Modulus, - Pipe, EndPipe, + Pipe, Not, Equal, NotEqual, Less, Greater, Pipeline, Arrow, @@ -62,7 +62,6 @@ impl std::fmt::Display for Token { Token::Greater => write!(f, ">"), Token::Pipeline => write!(f, "|>"), Token::Pipe => write!(f, "|"), - Token::EndPipe => write!(f, "\\"), Token::Arrow => write!(f, "->"), Token::Assign => write!(f, "="), @@ -102,7 +101,6 @@ pub fn lexer() -> impl Parser, Error = Simple> { just("|>").to(Token::Pipeline), just("|").to(Token::Pipe), - just("\\").to(Token::EndPipe), just('<').to(Token::Less), just('>').to(Token::Greater), diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 9616ce6..b11fe6e 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -317,7 +317,8 @@ fn expr_parser() -> impl Parser>, Error = Simple .repeated() ) .then( - just(Token::EndPipe) + just(Token::Pipe) + .ignore_then(just(Token::KwElse)) .ignore_then(expr.clone()) .then_ignore(just(Token::SemiColon)) ) diff --git a/example/case.hz b/example/case.hz index 6cc65d9..6ef53bb 100644 --- a/example/case.hz +++ b/example/case.hz @@ -7,6 +7,6 @@ fun main: void = do | 3 -> do @write("Three"); end; - \ @write("idk"); + | else @write("idk"); end; -end; \ No newline at end of file +end; diff --git a/example/factorial.hz b/example/factorial.hz index 834c8f5..f58f6a5 100644 --- a/example/factorial.hz +++ b/example/factorial.hz @@ -1,7 +1,7 @@ fun factorial (n: int): int = do case n of | 0 -> return 1; - \ return n * factorial(n - 1); + | else return n * factorial(n - 1); end; end; diff --git a/example/fibonacci.hz b/example/fibonacci.hz index 3db2e37..7c93d1e 100644 --- a/example/fibonacci.hz +++ b/example/fibonacci.hz @@ -8,4 +8,4 @@ end; fun main: void = do fib(5) |> @write(_); -end; \ No newline at end of file +end;