diff --git a/crates/lexer/src/lib.rs b/crates/lexer/src/lib.rs index 3cc9506..a8c9357 100644 --- a/crates/lexer/src/lib.rs +++ b/crates/lexer/src/lib.rs @@ -6,7 +6,7 @@ pub enum Token { KwLet, KwMut, KwFun, KwDo, KwEnd, KwIf, KwThen, KwElse, - KwMatch, KwWith, + KwCase, KwOf, KwReturn, KwPub, @@ -41,8 +41,8 @@ impl std::fmt::Display for Token { Token::KwIf => write!(f, "if"), Token::KwThen => write!(f, "then"), Token::KwElse => write!(f, "else"), - Token::KwMatch => write!(f, "match"), - Token::KwWith => write!(f, "with"), + Token::KwCase => write!(f, "case"), + Token::KwOf => write!(f, "of"), Token::KwReturn => write!(f, "return"), Token::KwPub => write!(f, "pub"), @@ -134,8 +134,8 @@ pub fn lexer() -> impl Parser, Error = Simple> { "if" => Token::KwIf, "then" => Token::KwThen, "else" => Token::KwElse, - "match" => Token::KwMatch, - "with" => Token::KwWith, + "case" => Token::KwCase, + "of" => Token::KwOf, "return" => Token::KwReturn, "pub" => Token::KwPub, _ => Token::Identifier(s), diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index ccbea32..3a85b90 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -335,9 +335,9 @@ fn expr_parser() -> impl Parser>, Error = Simple ) }); - let match_ = just(Token::KwMatch) + let match_ = just(Token::KwCase) .ignore_then(expr.clone()) - .then_ignore(just(Token::KwWith)) + .then_ignore(just(Token::KwOf)) .then( just(Token::Pipe) .ignore_then(expr.clone()) diff --git a/example/factorial.hz b/example/factorial.hz index c0cea7c..3e3cb07 100644 --- a/example/factorial.hz +++ b/example/factorial.hz @@ -1,18 +1,10 @@ fun factorial (n: int) : int = do - match n with + case n of | 0 -> return 1 | else return n * factorial(n - 1) end end -fun also_factorial (n: int) : int = do - if n == 0 then - return 1 - else - return n * also_factorial(n - 1) - end -end - fun main : void = do let result : int = factorial(5) @write(result) diff --git a/example/fibonacci.hz b/example/fibonacci.hz index 586653f..be8cac9 100644 --- a/example/fibonacci.hz +++ b/example/fibonacci.hz @@ -1,8 +1,8 @@ fun fib (n: int): int = do - if n < 2 then - return n - else - return fib(n - 1) + fib(n - 2) + case n of + | 1 -> return 1 + | 2 -> return 1 + | else -> return fib(n - 1) + fib(n - 2) end end diff --git a/example/hello.hz b/example/hello.hz new file mode 100644 index 0000000..55a80ea --- /dev/null +++ b/example/hello.hz @@ -0,0 +1,3 @@ +fun main: void = do + @write("Hello, World!") +end \ No newline at end of file diff --git a/example/io/emit.hz b/example/io/emit.hz deleted file mode 100644 index e4d9090..0000000 --- a/example/io/emit.hz +++ /dev/null @@ -1,3 +0,0 @@ -fun main: void = do - @emit("console.log('Hello, World!')"); -end; \ No newline at end of file diff --git a/example/io/hello.hz b/example/io/hello.hz deleted file mode 100644 index a014ee4..0000000 --- a/example/io/hello.hz +++ /dev/null @@ -1,3 +0,0 @@ -fun main: void = do - @write("Hello, World!"); -end; \ No newline at end of file diff --git a/example/io/read.hz b/example/io/read.hz deleted file mode 100644 index f6bd55e..0000000 --- a/example/io/read.hz +++ /dev/null @@ -1,14 +0,0 @@ -fun say_hi (name: string): void = do - @write("Hi "); - @write(name); - @write("!"); -end; - -fun main: void = do - let input: string = @read("Enter your name:"); - - match input with - | "" -> @write("I don't know your name :("); - \ say_hi(input); - end; -end; diff --git a/example/io/read_file.hz b/example/io/read_file.hz deleted file mode 100644 index b7af16c..0000000 --- a/example/io/read_file.hz +++ /dev/null @@ -1,5 +0,0 @@ --- Run this file from root path -fun main: void = do - @read_file("./example/io/read_file.hz") - |> @write(_); -end; \ No newline at end of file diff --git a/example/io/write_file.hz b/example/io/write_file.hz deleted file mode 100644 index f205262..0000000 --- a/example/io/write_file.hz +++ /dev/null @@ -1,3 +0,0 @@ -fun main: void = do - @write_file("console.log('Hello, World!')", "hello.js"); -end; \ No newline at end of file diff --git a/example/rule110.hz b/example/rule110.hz index 319033a..59d1518 100644 --- a/example/rule110.hz +++ b/example/rule110.hz @@ -1,5 +1,5 @@ fun print_single (cell: bool): void = do - match cell with + case cell of | true -> @write("█") | else @write(" ") end @@ -47,7 +47,7 @@ fun cell_merger (a: bool) (b: bool) (c: bool): bool = do end fun next (state: vec_bool) (pointer: int): bool = do - match pointer with + case pointer of | 0 -> do let a: bool = false let b: bool = @get(state, 1) diff --git a/example/tuples.hz b/example/tuples.hz index 354e483..9ca8b40 100644 --- a/example/tuples.hz +++ b/example/tuples.hz @@ -16,7 +16,7 @@ end fun every (a : [any]) (b : [any]): bool = return every_(a, b, 0) fun eqTuples (a : [any]) (b : [any]) : bool = - match @len(a) == @len(b) with + case @len(a) == @len(b) of | true -> return every(a, b) | else return false end